Cocos Creator API

1.4.x

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

Scheduler

Module: cc

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'. *

Properties

PRIORITY_SYSTEM Number static

Priority level reserved for system services.

PRIORITY_NON_SYSTEM Number static

Minimum priority level for user scheduling.

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

Methods

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.
Noteļ¼šIt will affect EVERY scheduled selector / action.

name type description
timeScale Number

getTimeScale ( ) Number

Returns time scale of scheduler.

returns:

type: Number

update
(
  • dt
)

'update' the scheduler. (You should NEVER call this method, unless you know what you are doing.)

name type description
dt Number

delta time

scheduleCallbackForTarget
(
  • target
  • callback_fn
  • interval
  • repeat
  • delay
  • paused
)
deprecated

deprecated: since v3.4 please use .schedule

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.macro.REPEAT_FOREVER to let the action run continuously
delay is the amount of time the action will wait before it'll start

name type description
target Object
callback_fn Function
interval Number
repeat Number
delay Number
paused Boolean

examples:

//register a schedule to scheduler
var scheduler = cc.director.getScheduler();
scheduler.scheduleCallbackForTarget(this, function, interval, repeat, delay, !this._isRunning);

schedule
(
  • callback
  • target
  • interval
  • repeat
  • delay
  • paused
)

The schedule

name type description
callback Function
target Object
interval Number
repeat