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.
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.
@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), gunman.body->GetPosition()); ((CCSprite*)[gunman.sprite getChildByTag:0]).flipX = YES; }else if(dPad.direction == DPAD_RIGHT || dPad.direction == DPAD_UP_RIGHT || dPad.direction == DPAD_DOWN_RIGHT){ gunmanDirection = DPAD_RIGHT; gunman.body->ApplyForce(b2Vec2(35.0f,0), gunman.body->...