Syncing the Background to Character Movement
In Chapter 8, solutions were presented for creating a multi-layered background that could scroll. However, you might be having problems if you tried to sync the scrolling of the background with the movement of the character.
In this chapter, you will be presented with two recipes—the first for scrolling a multi-image background in two directions, and the second for syncing the scrolling of that background with the movement of the playable character.
9.1 Scroll the Background in Two Directions
The background scrolls only in one direction when the player can run in two.
Modify the background class to track movement in two directions.
How It Works
This solution assumes ...