Scheduler
Class
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.<br/>
- custom callback: A custom callback will be called every frame, or with a custom interval of time<br/>
The 'custom selectors' should be avoided when possible. It is faster,
and consumes less memory to use the 'update callback'. *
Index
Properties
PRIORITY_SYSTEM
Number
Priority level reserved for system services.PRIORITY_NON_SYSTEM
Number
Minimum priority level for user scheduling.
Methods
enableForTarget
!en This method should be called for any target which needs to schedule tasks, and this method should be called before any scheduler API usage.setTimeScale
Default is 1.0.getTimeScale
Returns time scale of scheduler.update
'update' the scheduler.schedule
...
scheduleUpdate
Schedules the update callback for a given target,...unschedule
Unschedules a callback for a callback and a given target.unscheduleUpdate
Unschedules the update callback for a given target.unscheduleAllForTarget
Unschedules all scheduled callbacks for a given target.unscheduleAll
Unschedules all scheduled callbacks from all targets including the system callbacks....unscheduleAllWithMinPriority
Unschedules all callbacks from all targets with a minimum priority....isScheduled
Checks whether a callback for a given target is scheduled.pauseAllTargets
Pause all selectors from all targets....pauseAllTargetsWithMinPriority
Pause all selectors from all targets with a minimum priority.resumeTargets
Resume selectors on a set of targets....pauseTarget
Pauses the target....resumeTarget
Resumes the target....isTargetPaused
Returns whether or not the target is paused.
Details
Properties
PRIORITY_SYSTEM
Priority level reserved for system services.
meta | description |
---|---|
Type | Number |
Defined in | cocos2d/core/CCScheduler.js:1092 |
PRIORITY_NON_SYSTEM
Minimum priority level for user scheduling.
meta | description |
---|---|
Type | Number |
Defined in | cocos2d/core/CCScheduler.js:1101 |
Methods
enableForTarget
!en This method should be called for any target which needs to schedule tasks, and this method should be called before any scheduler API usage.
This method will add a _id
property if it doesn't exist.
!zh 任何需要用 Scheduler 管理任务的对象主体都应该调用这个方法,并且应该在调用任何 Scheduler API 之前调用这个方法。
这个方法会给对象添加一个 _id
属性,如果这个属性不存在的话。
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:351 |
Parameters
target
Object
setTimeScale
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.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:370 |
Parameters
timeScale
Number
getTimeScale
Returns time scale of scheduler.
meta | description |
---|---|
Returns | Number |
Defined in | cocos2d/core/CCScheduler.js:390 |
update
'update' the scheduler. (You should NEVER call this method, unless you know what you are doing.)
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:400 |
Parameters
dt
Number delta time
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
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:486 |
Parameters
Examples
//register a schedule to scheduler
cc.director.getScheduler().schedule(callback, this, interval, !this._isRunning);
scheduleUpdate
Schedules the update callback for a given target, During every frame after schedule started, the "update" function of target will be invoked.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:579 |
Parameters
unschedule
Unschedules a callback for a callback and a given target.
If you want to unschedule the "update", use unscheduleUpdate()
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:641 |
Parameters
unscheduleUpdate
Unschedules the update callback for a given target.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:698 |
Parameters
target
Object The target to be unscheduled.
unscheduleAllForTarget
Unschedules all scheduled callbacks for a given target. This also includes the "update" callback.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:728 |
Parameters
target
Object The target to be unscheduled.
unscheduleAll
Unschedules all scheduled callbacks from all targets including the system callbacks.
You should NEVER call this method, unless you know what you are doing.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:776 |
unscheduleAllWithMinPriority
Unschedules all callbacks from all targets with a minimum priority.
You should only call this with PRIORITY_NON_SYSTEM_MIN
or higher.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:789 |
Parameters
minPriority
Number The minimum priority of selector to be unscheduled. Which means, all selectors whichpriority is higher than minPriority will be unscheduled.
isScheduled
Checks whether a callback for a given target is scheduled.
meta | description |
---|---|
Returns | Boolean |
Defined in | cocos2d/core/CCScheduler.js:843 |
Parameters
pauseAllTargets
Pause all selectors from all targets.
You should NEVER call this method, unless you know what you are doing.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:889 |
pauseAllTargetsWithMinPriority
Pause all selectors from all targets with a minimum priority.
You should only call this with kCCPriorityNonSystemMin or higher.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:902 |
Parameters
minPriority
Number
resumeTargets
Resume selectors on a set of targets.
This can be useful for undoing a call to pauseAllCallbacks.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:962 |
Parameters
targetsToResume
Array
pauseTarget
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.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:981 |
Parameters
target
Object
resumeTarget
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.
meta | description |
---|---|
Defined in | cocos2d/core/CCScheduler.js:1020 |
Parameters
target
Object
isTargetPaused
Returns whether or not the target is paused.
meta | description |
---|---|
Returns | Boolean |
Defined in | cocos2d/core/CCScheduler.js:1059 |
Parameters
target
Object