Game Mechanics Method for infinite scrolling?

N

Noizee

Guest
Can anyone hand me some methods for an infinite scrolling mechanic?

Not only the inifinte scrolling, but also like when in vertical shooter games, a method on how to spawn enemies in a certain order and position.

A gm project would be fine too, if anyone has an example.

Thanks!
 
The way I did it in my project, Open Ocean, was to tile the background (This is just a checkbox on the Layer for HoizontalTile and/or VerticalTile). Then, I moved the background (And all objects except the player/UI) in the opposite direction of the player's speed/direction. This gives the illusion that the player is moving towards it, even though the player object doesn't ever actually move. Assuming you're making a top-down space shooter, similar to, say Raiden Fighters, you could just move them down instead. The code would look similar to this (In a Step event):

Code:
// moves the background layer
var layer_id = layer_get_id("YOUR_BACKGROUND_LAYER_NAME_GOES_HERE"); // note: If this Layer name ever changes, need to change it here too!
layer_vspeed(layer_id, 1); // change the 1 to the speed that you want it to go
Look up Open Ocean on itch.io or Steam if you want to see this in action (I can't post links yet, my account is too new, sorry!).
 
Woops, I just realized I forgot to answer the second part of your question. To get enemies to spawn at a certain position, store some variable that constantly increases as you go (This could be based off speed, or, more practically, could just be a timer). Once this variable gets to a certain number, spawn your enemies in the position that you want off the screen and have them move onto the screen. You'll probably want to use the instance_create, instance_create_depth, or instance_create_layer functions for that.
 

Yal

🐧 *penguin noises*
GMC Elder
Woops, I just realized I forgot to answer the second part of your question. To get enemies to spawn at a certain position, store some variable that constantly increases as you go (This could be based off speed, or, more practically, could just be a timer). Once this variable gets to a certain number, spawn your enemies in the position that you want off the screen and have them move onto the screen. You'll probably want to use the instance_create, instance_create_depth, or instance_create_layer functions for that.
A variation of this: have a ds_queue filled with scripts. If there's no enemies present, pop the script at the front of the queue and execute it. The script could spawn enemies, change the scrolling background, spawn other things, set a timer to proceed to the next script even if enemies are present, change the music (good for bosses)... and move you to the next room once all enemies in the level are defeated. Really flexible and easy to use! (I use this system in my YaruDanmakuEngine)

The reason I'm saying "proceed when no enemies are present" is that it makes the pace dynamically adjust, I find it hard to find good timings between enemy waves if you only operate on a timer - if the player is too good you get big empty boring stretches, if they're too bad they're overhwhelmed.
 
N

Noizee

Guest
Thank you both. I'll be checking that info.
The way I did it in my project, Open Ocean, was to tile the background (This is just a checkbox on the Layer for HoizontalTile and/or VerticalTile). Then, I moved the background (And all objects except the player/UI) in the opposite direction of the player's speed/direction. This gives the illusion that the player is moving towards it, even though the player object doesn't ever actually move. Assuming you're making a top-down space shooter, similar to, say Raiden Fighters, you could just move them down instead. The code would look similar to this (In a Step event):
But, how would you move all other instances? I mean, your method at least.

EDIT:
I coded this by warping the player when it passes a point in the room, it worked perfectly, though I didn't coded the warping of the rest of the objects.

But I noticed that I want to spawn all the items and enemies while you walk along. So I tried just erasing the warping code and letting the room as it was.
I noticed that I coluld let the background repeating endlessly even outside the room, which is awesome (my camera is not the built-in so it follows the player even outside the room).

My question is, should I let my warping code aside, or does working outside the room has some serious limitation I am not aware of and would be meaningful to know?
Also, does this means the room is actually endless?
 
Last edited by a moderator:

Director_X

Member
Hi. I'm trying to create an "infinite" room as well - and the above info is very helpful. Thanks. :)

How does moving the background deal with actual physical room size? I have various objects placed across the actual physical room (eg spawners in certain locations, and exit points).

Since moving the background is merely an illusion since the player is not physically moving, so how do we parse actual physical spawner objects and collision detection locations? Thanks.
 
Top