O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

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

Character movement

Moving a character around a level can be trickier than you might expect. In this recipe, we will lay out the basics of 2D side scrolling character movement.

Character movement

Getting ready

Please refer to the project RecipeCollection02 for full working code of this recipe. Also note that some of the following code has been omitted for brevity.

How to do it...

Execute the following code:

@implementation SideScrollerRecipe -(void) step:(ccTime)delta { [super step:delta]; //Apply gunman running direction if(dPad.direction == DPAD_LEFT || dPad.direction == DPAD_UP_LEFT || dPad.direction == DPAD_DOWN_LEFT){ gunmanDirection = DPAD_LEFT; gunman.body->ApplyForce(b2Vec2(-35.0f,0), ...

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