Game Development Reference
In-Depth Information
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 be-
ing larger than the screen, and to add the impression of depth to the world, you'll also im-
plement 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.
Listing 3-1 . Add these ivars to the GameScene class
@implementation GameScene
{
__weak CCNode* _levelNode;
__weak CCPhysicsNode* _physicsNode;
__weak CCNode* _playerNode;
__weak CCNode* _backgroundNode;
}
This code declares private variables (known as ivars ) named _levelNode , _physic-
sNode , _playerNode , and _backgroundNode . They are private because they are
Search WWH ::




Custom Search