Chapter 9
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
Problem
The background scrolls only in one direction when the player can run in two.
Solution
Modify the background class to track movement in two directions.
How It Works
This solution assumes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access