How do I make an infinite scrolling background?

  • Good night! I want to make a menu screen where a ship flies through space, and for that I need a background that scrolls infinitely, but after searching and reading this guide, I still am unable to make it work, even though I'm folowwing the guide. I want the background to scroll backwards, but it isn't doing that at all even if I follow the guide directed to scrolling left. Can anyone help me?

  • Could you share your screenshot or demo?

    We will know where it was wrong.

  • In this example he uses a speed variable that is worth 400. It would be the same as if he had said set y to TiledBackground.Y + 400 * dt. (Without the variable). So I hope you noticed that there is a global variable at the beginning of the event, if you didn't create the variable, nothing happens. You can just do it without the variable as I informed above. And you can use self in place of the object name, which is an expression that refers to the object itself, without having to type the name.

    It would look like this: set y to self.Y + 400 * dt (I tested it and it worked). And note that the tiled background must be twice the size of the layout (Always for this method), because when it reaches half the screen it goes back to the beginning. / But I said all this just for you to understand the operation and not just decorate.

    Simply use a tiled background the right size of the layout and in Every tick - / Tiledbackground - set image y offset- Self.ImageOffsetY + 400 * dt condition

    What is it? At each tick, select the tiled background object and choose the set image y offset action, which basically moves the tiled background object in the direction you want to repeat endlessly. It scrolls the image within the image itself, without needing to have an image twice the size. Then the code means self (the object itself and imageoffsety + add 400 to that scroll.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • E mais uma coisa, não precisa colocar os outros eventos, só essa linha de código da foto.

  • lincolnsallesThis is an English-language forum, and posts must therefore be in English, or at least include an English translation. Please ensure you follow this rule in future.

  • Note that you should wrap around the image offset back to 0 rather than letting it increase forever, because on some GPUs, large image offsets cause the image rendering quality to degrade.

  • You can wrap the offset without having to use additional conditions by using the modulo (%) expression in the action:

    -> TiledBackground: Set image X offset to ((Self.ImageWidth+Self.ImageOffsetX+backgroundSpeed*dt)%Self.ImageWidth

    This will automatically reposition the offset once it exceeds the image width.

    It's worth using a variable for the background speed rather than a fixed variable as it allows you to easily manipulate the background movement during play.

    A negative backgroundSpeed value will reverse the direction of movement.

    Switch width to height and X to Y for vertical movement.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)