Game Mechanics Method for infinite scrolling?

Discussion in 'Game Design, Development And Publishing' started by Noizee, Jun 4, 2019.

  1. Noizee

    Noizee Member

    Joined:
    Sep 17, 2016
    Posts:
    16
    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!
     
  2. Paul Kankiewicz

    Paul Kankiewicz Member

    Joined:
    Jun 5, 2019
    Posts:
    6
    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!).
     
    Noizee likes this.
  3. Paul Kankiewicz

    Paul Kankiewicz Member

    Joined:
    Jun 5, 2019
    Posts:
    6
    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.
     
    Noizee likes this.
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,460
    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.
     
  5. Noizee

    Noizee Member

    Joined:
    Sep 17, 2016
    Posts:
    16
    Thank you both. I'll be checking that info.
    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: Jun 10, 2019
  6. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,460
    Pretty simple:
    Code:
    with(all){
      if(object_index != obj_player){
         x -= global.player_horizontal_speed
         y -= global.player_vertical_speed
      }
    }
    
     
    Noizee likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice