Map scrolling
Root / Programming Questions / [.]
jmorgan98Created:
Make a variable for the x and y coords of your character, then put those 2 variables in bgofs 0,x,y. Boom scrollabe bg whenever you press a button.
Oh yeah, put bgofs in the button input/ replace your spofs that you probably put. If you already had your chr moving with variables and such then just change sp to bg in the ofs.
Here's the code I used in my game: (XX and YY are the character's sprite coordinates)
IF XX>384 AND SCREEN==1 THEN 'if we're at the edge of the screen and at the first screen BGANIM 3,0,1,X+400,Y 'move the screen (I'm using BG layer 3) XX=0 'move our character to the left edge of the screen SCREEN=2 'indicates that we're now on the second screen SPOFS 1,XX,YY 'moves our characterYou could then mirror this for the other four edges. It's important to note, however, that SCREEN is a variable I manage in the program to tell the program what screen the player is on and if your world was much larger there would be many more screens where the player could move to the right; and when you're moving the map to where it was originally you would use BGANIM 3,0,1,X,Y because X and Y represent the original coords of the bg layer (I think). This is code for moving the character and bg layer to the right.
jmorgan, I made this in one of my programs (Platform Example).
What you should do is detect when the player is about to exit the screen. Then, set the player movement to 0(depending to the axis he is moving) and move everything else with a velocity equal to the negative value of the player speed.
This could be done with BGOFS and SPOFS but if you don't want to iterate on every sprite, then set a sprite that would act as the "camera" and link it with every other sprite. When the player is moving out of the screen, move the background and the camera as described above.