Scheduler 类型

模块: cc

Scheduler 是负责触发回调函数的类。
通常情况下,建议使用 cc.director.getScheduler() 来获取系统定时器。
有两种不同类型的定时器:

- update 定时器:每一帧都会触发。您可以自定义优先级。<br/>
- 自定义定时器:自定义定时器可以每一帧或者自定义的时间间隔触发。<br/>

如果希望每帧都触发,应该使用 update 定时器,使用 update 定时器更快,而且消耗更少的内存。

索引

属性(properties)
方法

Details

属性(properties)

PRIORITY_SYSTEM

系统服务的优先级。

meta description
类型 Number
定义于 cocos2d/core/CCScheduler.js:1141
PRIORITY_NON_SYSTEM

用户调度最低优先级。

meta description
类型 Number
定义于 cocos2d/core/CCScheduler.js:1150

方法

setTimeScale

设置时间间隔的缩放比例。
您可以使用这个方法来创建一个 “slow motion(慢动作)” 或 “fast forward(快进)” 的效果。
默认是 1.0。要创建一个 “slow motion(慢动作)” 效果,使用值低于 1.0。
要使用 “fast forward(快进)” 效果,使用值大于 1.0。
注意:它影响该 Scheduler 下管理的所有定时器。

meta description
定义于 cocos2d/core/CCScheduler.js:363
参数列表
getTimeScale

获取时间间隔的缩放比例。

meta description
返回 Number
定义于 cocos2d/core/CCScheduler.js:383
update

update 调度函数。(不应该直接调用这个方法,除非完全了解这么做的结果)

meta description
定义于 cocos2d/core/CCScheduler.js:393
参数列表
scheduleCallbackForTarget

指定回调函数,调用对象等信息来添加一个新的定时器。</br> 当时间间隔达到指定值时,设置的回调函数将会被调用。</br> 如果 paused 值为 true,那么直到 resume 被调用才开始计时。</br> 如果 interval 值为 0,那么回调函数每一帧都会被调用,但如果是这样, 建议使用 scheduleUpdateForTarget 代替。</br> 如果回调函数已经被定时器使用,那么只会更新之前定时器的时间间隔参数,不会设置新的定时器。
repeat 值可以让定时器触发 repeat + 1 次,使用 cc.macro.REPEAT_FOREVER 可以让定时器一直循环触发。
delay 值指定延迟时间,定时器会在延迟指定的时间之后开始计时。

meta description
定义于 cocos2d/core/CCScheduler.js:483
废弃(Deprecated) since v3.4 please use .schedule
参数列表
示例
//register a schedule to scheduler
var scheduler = cc.director.getScheduler();
scheduler.scheduleCallbackForTarget(this, function, interval, repeat, delay, !this._isRunning);
schedule

定时器

meta description
定义于 cocos2d/core/CCScheduler.js:521
参数列表
示例
//register a schedule to scheduler
cc.director.getScheduler().schedule(callback, this, interval, !this._isRunning);
scheduleUpdate

使用指定的优先级为指定的对象设置 update 定时器。 update 定时器每一帧都会被触发。优先级的值越低,定时器被触发的越早。

meta description
定义于 cocos2d/core/CCScheduler.js:589
参数列表
unschedule

根据指定的回调函数和调用对象。 如果需要取消 update 定时器,请使用 unscheduleUpdate()。

meta description
定义于 cocos2d/core/CCScheduler.js:647
参数列表
  • callback Function The callback to be unscheduled
  • target Object The target bound to the callback.
unscheduleUpdate

取消指定对象的 update 定时器。

meta description
定义于 cocos2d/core/CCScheduler.js:696
参数列表
  • target Object The target to be unscheduled.
unscheduleAllForTarget

取消指定对象的所有定时器,包括 update 定时器。

meta description
定义于 cocos2d/core/CCScheduler.js:718
参数列表
  • target Object The target to be unscheduled.
unscheduleAll

取消所有对象的所有定时器,包括系统定时器。
不用调用此函数,除非你确定你在做什么。

meta description
定义于 cocos2d/core/CCScheduler.js:758
unscheduleAllWithMinPriority

取消所有优先级的值大于指定优先级的定时器。
你应该只取消优先级的值大于 PRIORITY_NON_SYSTEM_MIN 的定时器。

meta description
定义于 cocos2d/core/CCScheduler.js:771
参数列表
  • minPriority Number The minimum priority of selector to be unscheduled. Which means, all selectors which
     priority is higher than minPriority will be unscheduled.
    
isScheduled

检查指定的回调函数和回调对象组合是否存在定时器。

meta description
返回 Boolean
定义于 cocos2d/core/CCScheduler.js:825
参数列表
  • callback Function The callback to check.
  • target Object The target of the callback.
pauseAllTargets

暂停所有对象的所有定时器。
不要调用这个方法,除非你知道你正在做什么。

meta description
定义于 cocos2d/core/CCScheduler.js:863
pauseAllTargetsWithMinPriority

暂停所有优先级的值大于指定优先级的定时器。
你应该只暂停优先级的值大于 PRIORITY_NON_SYSTEM_MIN 的定时器。

meta description
定义于 cocos2d/core/CCScheduler.js:876
参数列表
resumeTargets

恢复指定数组中所有对象的定时器。
这个函数是 pauseAllCallbacks 的逆操作。

meta description
定义于 cocos2d/core/CCScheduler.js:936
参数列表
pauseTarget

暂停指定对象的定时器。
指定对象的所有定时器都会被暂停。
如果指定的对象没有定时器,什么也不会发生。

meta description
定义于 cocos2d/core/CCScheduler.js:955
参数列表
resumeTarget

恢复指定对象的所有定时器。
指定对象的所有定时器将继续工作。
如果指定的对象没有定时器,什么也不会发生。

meta description
定义于 cocos2d/core/CCScheduler.js:986
参数列表
isTargetPaused

返回指定对象的定时器是否暂停了。

meta description
返回 Boolean
定义于 cocos2d/core/CCScheduler.js:1019
参数列表
scheduleUpdateForTarget

为指定对象设置 update 定时器。
update 定时器每一帧都会被调用。
优先级的值越低,越早被调用。

meta description
定义于 cocos2d/core/CCScheduler.js:1043
废弃(Deprecated) since v3.4 please use .scheduleUpdate
参数列表
示例
//register this object to scheduler
var scheduler = cc.director.getScheduler();
scheduler.scheduleUpdateForTarget(this, priority, !this._isRunning );
unscheduleCallbackForTarget

根据指定的回调函数和调用对象对象取消相应的定时器。
如果需要取消 update 定时器,请使用 unscheduleUpdateForTarget()。

meta description
定义于 cocos2d/core/CCScheduler.js:1064
废弃(Deprecated) since v3.4 please use .unschedule
参数列表
示例
//unschedule a callback of target
var scheduler = cc.director.getScheduler();
scheduler.unscheduleCallbackForTarget(this, callback);
unscheduleUpdateForTarget

取消指定对象的所有定时器。

meta description
定义于 cocos2d/core/CCScheduler.js:1082
废弃(Deprecated) since v3.4 please use .unschedule
参数列表
示例
//unschedules the "update" method.
var scheduler = cc.director.getScheduler();
scheduler.unscheduleUpdateForTarget(this);
unscheduleAllCallbacksForTarget

取消指定对象的所有定时器,包括 update 定时器。

meta description
定义于 cocos2d/core/CCScheduler.js:1095
废弃(Deprecated) since v3.4 please use unscheduleAllForTarget
参数列表
unscheduleAllCallbacks

取消所有对象的所有定时器。
不要调用这个方法,除非你知道你正在做什么。

meta description
定义于 cocos2d/core/CCScheduler.js:1109
废弃(Deprecated) since v3.4 please use .unscheduleAllWithMinPriority
unscheduleAllCallbacksWithMinPriority

取消所有优先级的值大于指定优先级的所有对象的所有定时器。
你应该只暂停优先级的值大于 PRIORITY_NON_SYSTEM_MIN 的定时器。

meta description
定义于 cocos2d/core/CCScheduler.js:1124
废弃(Deprecated) since v3.4 please use .unscheduleAllWithMinPriority
参数列表

results matching ""

    No results matching ""