How to make an Infinite Platformer?

Triangularity GamesTriangularity Games Founder/OwnerMarylandMember Posts: 140
edited August 2017 in Working with GS (Mac)

I am trying to make an infinite platformer that is randomly generated. What would be the best way of accomplishing this? I have tried moving the player across the scene, but that proves difficult if you have to keep extending the scene. I feel the best way to accomplish this is to make the player still and move everything else within the screen (no scene size changes). However, after trying this I can't come up with a way for the ground to be infinite, either by spawning itself, or having two that move across the screen and then back to their original starting point (off screen). Essentially I am trying to make an infinite conveyor belt for which I can put obstacles and enemies on, but the important part is creating this infinite conveyor belt. Any help/advice would be greatly appreciated. Thanks in advance!

Best Answers

  • pHghostpHghost London, UKPosts: 2,342
    Accepted Answer

    What problem do you have with the two methods you describe? I've used both successfully before.

    I generally prefer the second method. I would use use three actors, each about 2/3 of the screen width. Then make a rule, if at x or smaller, teleport to current x + 2 * width.

    Make sure the rule is x or smaller (or bigger, depending on the direction), NOT when x = a value, because the actor might never hit that specific x, one frame it is at -99.342 and next frame at -100.056, which means it will never be at -100 exactly, for example.

  • pHghostpHghost London, UKPosts: 2,342
    Accepted Answer

    You can easily also make the scene so wide that it is pretty much impossible for the player to reach the end, so then you can move the player character. I've done that as well and it works. Actually, in my last game I used both methods, a veeery long scene and constantly moving actors for the background.

  • pHghostpHghost London, UKPosts: 2,342
    Accepted Answer

    @Triangularity Games said:
    I feel like at some point though, this would cause the game to be very large and laggy. Was this the case?

    Nope, not the case. The scene size makes either none, or very minimal difference with game size or lagginess -- that is, of you are spawning things. If you build the whole level, it will bring the size of the XML up a bit, but not critically.

    Of course, in my game, since it's essentially an infinite runner and you only go forward, I can destroy the actors once they are far back with a simple rule, so that brings the potential for lag radically down.

    @Triangularity Games said:
    The biggest problem I'm facing is the player being able to walk backwards when the ground is no longer there.

    Now, if you can only go back a little, that would still enable you to destroy everything further than that for memory management. My suggestion would be to decide how far back you want the character to be able to walk. Let's work with an example of 500 (from edge of actors, not middle, adjust according to actor widths).

    First, you will use more than the 3 platforms repositioning from the back forward. Enough to extend far enough. Even if you go a bit overboard for safety and use, say 8, it won't affect performance that much, so no worries.

    Second, make a game.attribute and constrain it to the main character's X (or the direction he is moving in). Then, create a barrier behind the character which will collide with the hero, not letting him past. The important logic in the barrier is IF game.hero.X - barrier.X > 500, THEN constrain barrier.X to game.hero.X + 500. This will move the barrier with the actor, but ONLY when going forward. When going back, it will stay in place and block the hero.

Answers

Sign In or Register to comment.