GMS 2.3+ Infinite Vertical Background

Sultown

Member
Preface
My apologies if this has already been covered somewhere. If so, please link it to me. I have done extensive searching on the forums and in videos, and either the solution is outdated (unsupported syntax) or it doesn't quite pertain to my issue. With that said:

Problem
I am trying to find an updated method (as of 12-10-20) to infinitely scroll a background layer vertically. The player should be able to move infinitely upward and infinitely downward. The background should not scroll horizontally, so the camera must remain static in that direction (which I can figure out another time). In essence I'm looking for a solution to loop the background non-dynamically, meaning the player can stop or slow down and the background will stay with the location of the player.

Kind regards.
 

kburkhart84

Firehammer Games
Instead of the player moving, make everything else move around the player. Some shooters do this. Then its only a matter of having some object be the background, and having two of those. When one is moving down and fully goes off-screen, it jumps to the top, and vice-versa. And you have two of them so they always fill the screen. You could also have a single object control this and simply draw the thing twice from that single object.

And if you make your game this way, the player can easily move around the screen while objects move around him. Enemies can spawn just off-screen and then come in. And you can have other objects that are just scenery go from top to bottom similar to the backgrounds if you would like.
 

Sultown

Member
Solution I Found
Create Event code in background object (no sprite)
GML:
layBackground = layer_get_id("Background");
Step Event code in background object
GML:
layer_vspeed(layBackground, 2);
Create event code runs once on creation (for performance).
Step event code runs every tick to update when changing direction or speed.
 
Top