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?

  • Ogeon@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    1 year 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…

  • bstix@feddit.dk
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 year 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.