I am programming a side-scrolling game.
I want to be able to control the speed of the endless side-scrolling background relative to the speed and position the player is moving at.
I want to know how to do a few things:
- Like, if the player is running, the background scrolls faster. If the
- Player is walking, the background scrolls slower. If the player isn’t
- Moving, the background shouldn’t be moving. If the it is at the start
- Or end of the level, the background should stop moving too.
Anyone can give me insight on how to do this?
There’s a simple formula that can do this for you:
Adjust the position of the background elements to be a percentage of the foreground elements. The lower the percentage, the slower they will move with the rest of the game.
Sample:
The
backgroundwill always move at 20% of the speed of theplayer. When theplayermoves 200 pixels, thebackgroundwill only scroll 40 pixels.