Game Development Reference
In-Depth Information
-(void) theDelayedMethod:(CCTime)delta
{
// Your code here ...
}
Caution You should never use NSTimer , any performSelector variant,
or Grand Central Dispatch methods like dispatch_after in a Cocos2D
game to schedule timed events. These timing methods do not pause automatic-
ally when the node or Cocos2D is paused, and with the exception of NSTimer
you can't even manually pause and resume them. You also don't know when
exactly in the update/render loop these timing methods will run, or whether
they'll reliable run in the same order. You should solely rely on the CCNode
scheduling methods mentioned earlier, or use a CCActionSequence that
contains both a CCActionDelay and either a CCActionCallBlock or
CCActionCallFunc to run code after a given time or at specific intervals.
The delta parameter is the delta time, or difference in time, since the last call to the up-
date: method. At 60 frames per second, delta time is usually around 0.0167. This value
is in seconds.
Delta time is generally used to move nodes at the same speed regardless of frame rate;
however, there are severe drawbacks to doing so. We won't be using delta time in this
topic because we're using Cocos2D's physics engine for movements. Physics games in
particular should slow down as the frame rate decreases rather than skipping frames and
moving ahead, thus leaving objects to advance greater distances per individual frame.
Moving the Level Node in the Opposite Direction
Of course, you'll also have to add the scrollToTarget: method in Listing 3-8 to the
GameScene.m as well complete the basic scrolling. The target parameter is our
_playerNode but instead of using the _playerNode ivar directly, I decided to pass it
in as a parameter. This enables you to scroll to different target nodes after you've com-
pleted the topic and are ready to extend the project.
Listing 3-8 . Scrolling to target requires a tiny bit of math
-(void) scrollToTarget:(CCNode*)target
Search WWH ::




Custom Search