Class cc.Scheduler

Class Summary
Constructor Attributes Constructor Name and Description
 

Scheduler is responsible of triggering the scheduled callbacks.

Method Summary

Class Detail

cc.Scheduler()

Scheduler is responsible of triggering the scheduled callbacks.
You should not use NSTimer. Instead use this class.

There are 2 different types of callbacks (selectors):
- update selector: the 'update' selector will be called every frame. You can customize the priority.
- custom selector: A custom selector will be called every frame, or with a custom interval of time

The 'custom selectors' should be avoided when possible. It is faster, and consumes less memory to use the 'update selector'. *

//register a schedule to scheduler
cc.Director.getInstance().getScheduler().scheduleSelector(selector, this, interval, !this._isRunning);

Method Detail

  • ctor()
    Constructor
  • {Number} getTimeScale()
    returns time scale of scheduler
    Returns:
    {Number}
  • {Boolean} isTargetPaused(target)
    Returns whether or not the target is paused
    Parameters:
    {cc.Class} target
    Returns:
    {Boolean}
  • pauseAllTargets()

    Pause all selectors from all targets.
    You should NEVER call this method, unless you know what you are doing.

  • pauseAllTargetsWithMinPriority(minPriority)
    Pause all selectors from all targets with a minimum priority.
    You should only call this with kCCPriorityNonSystemMin or higher.
    Parameters:
    minPriority
  • pauseTarget(target)

    Pauses the target.
    All scheduled selectors/update for a given target won't be 'ticked' until the target is resumed.
    If the target is not present, nothing happens.

    Parameters:
    {cc.Class} target
  • resumeTarget(target)
    Resumes the target.
    The 'target' will be unpaused, so all schedule selectors/update will be 'ticked' again.
    If the target is not present, nothing happens.
    Parameters:
    {cc.Class} target
  • resumeTargets(targetsToResume)
    Resume selectors on a set of targets.
    This can be useful for undoing a call to pauseAllCallbacks.
    Parameters:
    targetsToResume
  • scheduleCallbackForTarget(target, callback_fn, interval, repeat, delay, paused)

    The scheduled method will be called every 'interval' seconds.
    If paused is YES, then it won't be called until it is resumed.
    If 'interval' is 0, it will be called every frame, but if so, it recommended to use 'scheduleUpdateForTarget:' instead.
    If the callback function is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
    repeat let the action be repeated repeat + 1 times, use cc.REPEAT_FOREVER to let the action run continuously
    delay is the amount of time the action will wait before it'll start

    //register a schedule to scheduler
    cc.Director.getInstance().getScheduler().scheduleCallbackForTarget(this, function, interval, repeat, delay, !this._isRunning );
    Parameters:
    {cc.Class} target
    {function} callback_fn
    {Number} interval
    {Number} repeat
    {Number} delay
    {Boolean} paused
  • scheduleUpdateForTarget(target, priority, paused)

    Schedules the 'update' callback_fn for a given target with a given priority.
    The 'update' callback_fn will be called every frame.
    The lower the priority, the earlier it is called.

    //register this object to scheduler
    cc.Director.getInstance().getScheduler().scheduleUpdateForTarget(this, priority, !this._isRunning );
    Parameters:
    {cc.Class} target
    {Number} priority
    {Boolean} paused
  • setTimeScale(timeScale)

    Modifies the time of all scheduled callbacks.
    You can use this property to create a 'slow motion' or 'fast forward' effect.
    Default is 1.0. To create a 'slow motion' effect, use values below 1.0.
    To create a 'fast forward' effect, use values higher than 1.0.

    Parameters:
    {Number} timeScale
  • unscheduleAllCallbacks()

    Unschedules all function callbacks from all targets.
    You should NEVER call this method, unless you know what you are doing.

  • unscheduleAllCallbacksForTarget(target)
    Unschedules all function callbacks for a given target. This also includes the "update" callback function.
    Parameters:
    {cc.Class} target
  • unscheduleAllCallbacksWithMinPriority(minPriority)

    Unschedules all function callbacks from all targets with a minimum priority.
    You should only call this with kCCPriorityNonSystemMin or higher.

    Parameters:
    {Number} minPriority
  • unscheduleCallbackForTarget(target, callback_fn)

    Unschedule a callback function for a given target.
    If you want to unschedule the "update", use unscheudleUpdateForTarget.

    //unschedule a selector of target
    cc.Director.getInstance().getScheduler().unscheduleCallbackForTarget(function, this);
    Parameters:
    {cc.Class} target
    {function} callback_fn
  • unscheduleUpdateForTarget(target)
    Unschedules the update callback function for a given target
    //unschedules the "update" method.
    cc.Director.getInstance().getScheduler().unscheduleUpdateForTarget(this);
    Parameters:
    {cc.Class} target
  • update(dt)
    'update' the scheduler. (You should NEVER call this method, unless you know what you are doing.)
    Parameters:
    {Number} dt
    delta time