O'Reilly logo

Android Game Recipes: A Problem-Solution Approach by J. F. DiMarzio

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required