ACLS ' Clear screen XSCREEN 1 ' 2D screen DISPLAY 0 ' Top display BGSCREEN 0,25,15,16 ' Make a bg screen that is 25x15 and has 16pixel tiles ' I moved this to before you actually start moving the screen. Demonstration purposes. DIM X,Y,I FOR Y=0 TO 15-1 FOR X=0 TO 25-1 BGPUT 0,X,Y,Y*32+X NEXT X NEXT Y BGOFS 0,200,120 ' Move the top left corner to the center of the screen. [STOP] ' If you stopped now, you'd see that yes, you put the top left in the center of the screen. BGHOME 0,200,120 ' When moving objects, use the center point, not the top left point. [STOP] ' Now you see that the point being controlled with BGOFS is the middle point, not the top left. FOR I=0 TO 360-1 BGROT 0,I ' Rotate I degrees around the center point. VSYNC ' Wait a frame (Use VSYNC, it's ten times better for ridiculous technical reasons and has the exact same syntax) NEXT I
BG rotation and stuff
Root / Programming Questions / [.]
MZ952Created:
Can someone explain to me why this works?
ACLS XSCREEN 1 DISPLAY 0 BGSCREEN 0,25,15,16 BGOFS 0,200,120 BGHOME 0,200,120 DIM X,Y,I FOR Y=0 TO 15-1 FOR X=0 TO 25-1 BGPUT 0,X,Y,Y*32+X NEXT X NEXT Y FOR I=0 TO 360-1 BGROT 0,I WAIT NEXT ISo, my intention was to get the BG screen to rotate centered at the top screen (200,120), which this does, but I actually don't understand why it works. I just learned BG stuff like 2 minutes ago so don't judge. BGOFS shifts the BG tiles so that the origin of the BG screen (0,0) is now at 200,120. Okay, great. BGHOME supposedly changes where the center of rotation and scaling of the BG page is, which it does, but it also shifts the whole BG screen back -200,-120, which I don't understand. If BGHOME used the translated coordinates from BGOFS (origin from 0,0 to 200,120), that is, if it treats 200,120 as the relative origin, then I'd expect the rotation center to be at OriginX+200,OriginY+120, or 400,240. If it instead was relative to screen coordinates, then I'd expect the rotation center to be 200,120 relative to the screen. Seems to be the latter, but it somehow also shifts the whole thing. yeah, idk.
BGOFS shifts the BG tiles so that the origin of the BG screen (0,0) is now at 200,120. Okay, great. BGHOME supposedly changes where the center of rotation and scaling of the BG page is, which it does, but it also shifts the whole BG screen back -200,-120, which I don't understand.I think the main reason this is confusing you is because you're setting BGOFS, then BGHOME, so you're confused about why BGHOME seems to move the BG. BGOFS 0,X,Y doesn't move the top-left corner of the BG to that screen position. It moves the home to that screen position. In other words, if you were to set BGHOME to the center of that BG, then do BGOFS 0,100,100, then the center of the BG would be shown at screen position (100,100). (You may notice that it doesn't matter whether you do BGHOME then BGOFS, or BGOFS then BGHOME. It may seem weird that BGHOME sort of "retroactively" changes the position of the BG on-screen, but that's simply because BGs store the current home and current offset, rather than absolute screen position, and render based on both of those every frame.)
Page swapping is only useful when you want your game to run at less than 60FPS.
Anyway, BGHOME and BGOFS are swapped. (Not sure if this was intentional or a mistake, but they definitely didn't realize the full implications of this, if it was on purpose)
Use BGOFS to set the origin within the BG layer, and BGHOME to change the position.
This is especially noticeable when you scale the BG layer.
BGOFS uses BG pixels as its units, so BGOFS 0,16,16 will set the origin to the lower right corner of the first tile, no matter what the scale is.
BGHOME uses screen pixels for units, so it doesn't depend on the scale, and will position the BG layer so the origin is at that point on screen.