Chapter 3
Controlling and Scrolling
Most games need some way to control the player character. You’ll learn to use Cocos2D actions to move the player through the level you designed. Due to this project’s levels being larger than the screen, and to add the impression of depth to the world, you’ll also implement parallax scrolling as well.
Touch and Go: Moving the Player
The first order of business is to add code that reacts to touch events. You’ll use that to move the player around. To do so, you first have to establish a reference to the player node in the GameScene class.
Finding the Player Node by Its Name
In the GameScene.m class, add the brackets and variable declarations of Listing 3-1 just below the class’ @implementation section.
Get Learn SpriteBuilder for iOS Game Development 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.