I’m trying to make something in 2d where once the player reaches the end of the level, they’re back at the beginning and it just keeps going like that. I could imagine how this could be done in terms of setting the player position, but if I have a scrolling parallax background, how would I make that match up reliably?

  • @[email protected]
    link
    fedilink
    29 months ago

    Do you want the background to have looped back to the start after one cycle? If so, you probably have to make it repeat N times more than the foreground, and move by a factor of 1/N in comparison to the foreground. Or put another way, have 1/N times the length. That means that after one cycle, the background has moved a distance of 1/N, but also repeated exactly once.

    I hope this makes sense…

  • @[email protected]
    link
    fedilink
    English
    1
    edit-2
    9 months ago

    Either have the background sync up with the level at the place where the level loops, or don’t sync at all, by keeping two sets of player positions. One for the level, which you can reset when you want the player to restart and then one for the background which is reset/looped separately and independent on the level position.