Game Development Reference
change the object's position only in the next frame. But that's when you're
already stopping all actions again and adding another new MoveBy action.
Repeat ad infinitum , but the object will simply not move at all. It's like the
clichéd donkey: push it too hard, and it'll become a stubborn, immobile ob-
Let's go through the code changes. Add the playerVelocity variable to the head-
@interface GameLayer : CCLayer
If you wonder why I'm using a CGPoint instead of float , who's to say you'll never
want to accelerate up or down a little? So, it doesn't hurt to be prepared for future ex-
Listing 4-6 shows the accelerometer code, which I changed to use the velocity instead
of updating the player position directly. It introduces three new design parameters for
the amount of deceleration, the accelerometer sensitivity, and the maximum velocity.
Those are values that don't have an optimum; you need to tweak them and find the
right settings that work best with your game's design (which is why they're called
design parameters ).
Deceleration works by reducing the current velocity before adding the new accelero-
meter value multiplied by the sensitivity. The lower the deceleration, the quicker the
player can change the alien's direction. The higher the sensitivity, the more responsive
the player will react to accelerometer input. These values interact with each other be-
cause they modify the same value, so be sure to tweak only one value at a time.
-(void) accelerometer:(UIAccelerometer *)accelerometer