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 ...

Get Android Game Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.