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 callback: the 'update' callback will be called every frame. You can customize the priority.
- custom callback: A custom callback 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 callback'. *

//register a schedule to scheduler
cc.director.getScheduler().schedule(callback, this, interval, !this._isRunning);

Field Detail

<static> <constant> {Number} cc.Scheduler.PRIORITY_SYSTEM
Priority level reserved for system services.

Method Detail

  • {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:
    {Number} 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:
    {Array} 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.getScheduler().scheduleCallbackForTarget(this, function, interval, repeat, delay, !this._isRunning );
    Parameters:
    {cc.Class} target
    {function} callback_fn
    {Number} interval
    {Number} repeat
    {Number} delay
    {Boolean} paused
    Deprecated:
    since v3.4 please use .schedule
  • 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.getScheduler().scheduleUpdateForTarget(this, priority, !this._isRunning );
    Parameters:
    {cc.Class} target
    {Number} priority
    {Boolean} paused
    Deprecated:
    since v3.4 please use .scheduleUpdate
  • 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.

    Deprecated:
    since v3.4 please use .unscheduleAllWithMinPriority
  • unscheduleAllCallbacksForTarget(target)
    Unschedules all function callbacks for a given target. This also includes the "update" callback function.
    Parameters:
    {cc.Class} target
    Deprecated:
    since v3.4 please use .unscheduleAll
  • 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
    Deprecated:
    since v3.4 please use .unscheduleAllWithMinPriority
  • unscheduleCallbackForTarget(target, callback)

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

    //unschedule a callback of target
    cc.director.getScheduler().unscheduleCallbackForTarget(function, this);
    Parameters:
    {cc.Class} target
    {function} callback
    callback[Function] or key[String]
    Deprecated:
    since v3.4 please use .unschedule
  • unscheduleUpdateForTarget(target)
    Unschedules the update callback function for a given target
    //unschedules the "update" method.
    cc.director.getScheduler().unscheduleUpdateForTarget(this);
    Parameters:
    {cc.Class} target
    Deprecated:
    since v3.4 please use .unschedule
  • update(dt)
    'update' the scheduler. (You should NEVER call this method, unless you know what you are doing.)
    Parameters:
    {Number} dt
    delta time