Ways to move a stage in an endless runner

I have something like an endless runner in which the background is generated randomly on the fly. They are several layers of paralax type (8 or 12) and a character that in principle we cannot handle directly because the mechanics are different. The only thing he mainly does is advance in a scenario (maybe stop and go)

In how many ways can I do that, and what pros and cons does each one have? I can think of some:

  1. That there is always an action for the object to move on the X axis a certain number of pixels, those closest to the camera will move faster and those in the background slower. The problem is that if I want to make a stop, its a hard stop, not with ease. (I don’t know if with any function it is possible)

  2. Using tweens, so that each sprite that is generated assigns a speed and distance. But I can’t stop them halfway, or maybe I can?

  3. Assigning the behavior of top-down movements and simulating pressing the left or right key to advance the background. This version has everything because it has acceleration, I can configure maximum speed, front, back… the problem is that assigning this behavior to so many sprites at the same time I don’t know if it will be excessive.

For parallax backgrounds, just put all the objects on their own layer and then move the camera for that layer.

Your #1 and #2 ideas would work also. You can stop tweens at any time. But, it would still be easier to deal with entire layers rather than groups of many objects.

#3 idea, yeah, that would be excessive. You don’t need all the functionality of those behaviors for simple background objects that don’t do anything other than move past the camera.

1 Like

Whenever I have tried to separate things by layers then I have found that most effects can only be applied on one layer, and if you put it on several it is chaos.

How can I move the layer camera over time? I’m trying this but it doesn’t work:

image

Maybe with a external variable (x pos) and adding a number?

CameraCenterX() actually takes two arguments, the layer and camera number, which default to base layer and camera 0. Leaving it empty is the same as:

CameraCenterX(“”, 0)
or
CameraCenterX(“Base layer”, 0)

So for your action I think you need:

CameraCenterX(“l1”, 0) - 1

1 Like

Effects can be used directly on objects too, although doing it by layer is much faster as long as there’s more than one object.

I can imagine that some effects would “stack” badly, but it depends on what you’re using and your desired result. Which effects are you trying to use?

1 Like

You’re absolutely right, I forgot about which layer! Thank you!

Mmm, maybe I have to program the generation of the world in another way, because changing the camera instead of moving the sprite, the “end sprite” detectors don’t work.

Currently, when a background sprite moved from right to left, once it crossed the screen, it had a detector on the left to generate a new background sprite on the right. But of course, by just moving the camera, there is no collision.

Oops, I wrote this reply yesterday and just forgot to hit send… yes collisions won’t work like that. However you could instead check the position of the camera directly:

CameraCenterX(“l1”, 0) < background.X() - (half of screen width)

1 Like