• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 How can I make an infinitely long room?

T

Teo

Guest
I already have a basic platformer with levels setup but I want to make an endless gamemode, heres what I want to be able to do: I want to randomly generate preset chunks side by side to make an endless runner, I don't want to make random terrain but preset structures in a random order infinitely.
 
you can make a finit room size then move every thing except the level when you reach a sertaint point and aligne the end with the start


if x > 3000 {
x -= 2500
with obj_enemies {
x -= 2500
}
 
T

Teo

Guest
Thanks I'll try that, even though it isn't fully randomized it could work for what I'm doing, but if anyone knows a method to make it randomized as well.
 

NightFrost

Member
The basic idea with "infinite" rooms is that everything moves except the player. So if apparent motion is towards the right, everything moves left. They spawn beyond the right edge and get destroyed once they are past the left edge.
 

Bentley

Member
I already have a basic platformer with levels setup but I want to make an endless gamemode, heres what I want to be able to do: I want to randomly generate preset chunks side by side to make an endless runner, I don't want to make random terrain but preset structures in a random order infinitely.
This is a terrible solution (take the word "solution" with a grain of salt). And it's probably the most inelegant approach ever:

I created a background sprite that tiles horizontally. I made the room double the width of that sprite. I gave the room that background and checked "horizontally tile".

I then placed two objects, obj_wrap_right, obj_wrap_left. As long as you place them away from the sides then the view won't snap. I placed the wrap objects in the exact same location in terms of where they match up.

So let's say there's a mountain in your background. That mountain will appear twice, because you tiled the background twice. So place obj_wrap_right at the right mountain, and obj_wrap_left at the left mountain. Snap the player to the left when he reaches the right. Because obj_wrap_left is far enough away from the left side of the room, you won't notice the change in position.

Code:
// Move to the right object
x += min(5, point_distance(x, 0, obj_wrap_right.x, 0));

// Are you there? Wrap to the left object
if (x == obj_wrap_right.x)
{
    x = obj_wrap_left.x;
}
Obviously, I didn't do the left side. And let me restate, I just did this real quick like so yeah. But let me know if you try it and it works / helps.
 
Last edited:
Top