LoginLogin

Map scrolling

Root / Programming Questions / [.]

jmorgan98Created:
I'm fairly new to SMILEBasic, and I've learned how to load in sprites & backgrounds, and how to animate them, but I can't figure out how to make a map scroll when you move to the edge of it. Any ideas? Any help would be much appreciated, and thank you in advance.


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.

(I'm sorry if this sounds rude, I tried not to look sarcastic when I said this because I'm truly grateful.) That helps with a game where only the background scrolls, but I want it to where when my sprite touches the side of the screen, the background moves to accompany the moving sprite.

Do the exact same thing, but only when the character x is greater than your threshold at the edge of the screen.

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 character
You 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.

Thank you, I'll try these out tomorrow