Developers Manual > Cocos2d-x > Modules > Scheduler

Scheduler

Scheduler is responsible for triggering the scheduled callbacks.

Two different types of callbacks (selectors):

  • Update selector: the ‘update’ selector will be called every frame. You can customize the priority,the value of priority could be < 0, = 0 or >0, the priority that < 0 would be called first.
  • Custom selector: A custom selector will be called every frame, or with a custom interval of time or be paused until it is resumed.

Custom selectors should be avoided when possible. Update selectors are faster and consume less memory.

Scheduler vs. NSTimer

The Cocos2D Scheduler provides your game with timed events and calls. You should not use NSTimer. Instead use Scheduler class.

  • Node objects know how to schedule and unschedule events and using the Cocos2D Scheduler has several distinct advantages over just using NSTimer.
  • The scheduler calls get deactivated whenever the Node is no longer visible or is removed from the scene.
  • The scheduler calls are also deactivated when Cocos2D is paused and are rescheduled when Cocos2D is resumed.
  • The scheduler delivers an interval time of the milliseconds that have passed since the last call. This interval time is useful in physics engines.
  • Calling scheduleUpdate() for a Node object, it can ensure that your update function would be called before frame rendering.

Accordingly, Scheduler can save you a lot of time over NSTimer and let you focus on the mechanics of your game.

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.