Game Development Reference
In-Depth Information
If you haven't installed your development provisioning profiles in Xcode for this par-
ticular project yet, you'll get a "code sign" error. Code signing is required to run an app
on an iOS device. Refer to Apple's documentation to learn how to create and install the
necessary development provisioning profiles ( http://developer.apple.com/
ios/manage/provisioningprofiles/howto.action ) .
Player Velocity
Notice how the accelerometer input isn't quite right? It's reacting slowly, and the mo-
tion isn't fluid. That's because the player sprite doesn't experience true acceleration
and deceleration. Let's fix that now. You'll find the accompanying code changes in the
DoodleDrop03 project.
The concept for implementing acceleration and deceleration is not to change the play-
er's position directly but to use a separate CGPoint variable as a velocity vector.
Every time an accelerometer event is received, the velocity variable accumulates input
from the accelerometer. Of course, that means you also have to limit the velocity to an
arbitrary maximum; otherwise, it'll take too long to decelerate. The velocity is then ad-
ded to the player position every frame, regardless of whether accelerometer input was
received.
Note Why not use actions to move the player sprite? Well, move actions are a
bad choice whenever you want to change an object's speed or direction very of-
ten—say, multiple times per second. Actions are designed to be relatively long-
lived, one-shot objects; creating new ones frequently creates additional over-
head in terms of allocating and releasing memory. This can quickly drain a
game's performance.
Worse yet, actions don't work at all if you don't give them any time to do
their work. That's why adding a new action to replace the previous one every
frame won't show any effect whatsoever. Many cocos2d developers have
stumbled across this seemingly odd behavior.
For example, stopping all actions and then adding a new MoveBy action to an
object every frame won't make it move at all! The MoveBy action will
Search Nedrilad ::




Custom Search