• Scheduler 类型
    • 索引
      • 属性(properties)
      • 方法
  • Details
    • 属性(properties)
      • PRIORITY_SYSTEM
      • PRIORITY_NON_SYSTEM
        • 参数列表
      • setTimeScale
        • 参数列表
      • getTimeScale
      • update
        • 参数列表
      • schedule
        • 参数列表
      • 示例
      • scheduleUpdate
        • 参数列表
      • unschedule
        • 参数列表
      • unscheduleUpdate
        • 参数列表
      • unscheduleAllForTarget
        • 参数列表
      • unscheduleAll
      • unscheduleAllWithMinPriority
        • 参数列表
      • isScheduled
        • 参数列表
      • pauseAllTargets
      • pauseAllTargetsWithMinPriority
        • 参数列表
      • resumeTargets
        • 参数列表
      • pauseTarget
        • 参数列表
      • resumeTarget
        • 参数列表
      • isTargetPaused
        • 参数列表

    Scheduler 类型

    模块: cc

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

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

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

    索引

    属性(properties)
    • PRIORITY_SYSTEM Number 系统服务的优先级。
    • PRIORITY_NON_SYSTEM Number 用户调度最低优先级。
    方法
    • enableForTarget !zh 任何需要用 Scheduler 管理任务的对象主体都应该调用这个方法,并且应该在调用任何 Scheduler API 之前调用这个方法。
    • setTimeScale 设置时间间隔的缩放比例。
    • getTimeScale 获取时间间隔的缩放比例。
    • update update 调度函数。
    • schedule 指定回调函数,调用对象等信息来添加一个新的定时器。
    • scheduleUpdate 使用指定的优先级为指定的对象设置 update 定时器。
    • unschedule 取消指定对象定时器。
    • unscheduleUpdate 取消指定对象的 update 定时器。
    • unscheduleAllForTarget 取消指定对象的所有定时器,包括 update 定时器。
    • unscheduleAll 取消所有对象的所有定时器,包括系统定时器。
    • unscheduleAllWithMinPriority 取消所有优先级的值大于指定优先级的定时器。
    • isScheduled 检查指定的回调函数和回调对象组合是否存在定时器。
    • pauseAllTargets 暂停所有对象的所有定时器。
    • pauseAllTargetsWithMinPriority 暂停所有优先级的值大于指定优先级的定时器。
    • resumeTargets 恢复指定数组中所有对象的定时器。
    • pauseTarget 暂停指定对象的定时器。
    • resumeTarget 恢复指定对象的所有定时器。
    • isTargetPaused 返回指定对象的定时器是否暂停了。

    Details

    属性(properties)

    PRIORITY_SYSTEM
    系统服务的优先级。
    metadescription
    类型Number
    定义于cocos2d/core/CCScheduler.js:1092
    PRIORITY_NON_SYSTEM
    用户调度最低优先级。
    metadescription
    类型Number
    定义于cocos2d/core/CCScheduler.js:1101



    #### 方法



    ##### 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 属性,如果这个属性不存在的话。

    metadescription
    定义于cocos2d/core/CCScheduler.js:351
    参数列表
    • target Object
    setTimeScale

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:370
    参数列表
    • timeScale Number
    getTimeScale

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

    metadescription
    返回Number
    定义于cocos2d/core/CCScheduler.js:390
    update

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:400
    参数列表
    • dt Number delta time
    schedule

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:486
    参数列表
    • callback Function
    • target Object
    • interval Number
    • repeat Number
    • delay Number
    • paused Boolean
    示例
    1. //register a schedule to scheduler
    2. cc.director.getScheduler().schedule(callback, this, interval, !this._isRunning);
    scheduleUpdate

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:579
    参数列表
    • target Object
    • priority Number
    • paused Boolean
    unschedule

    取消指定对象定时器。如果需要取消 update 定时器,请使用 unscheduleUpdate()。

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

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

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

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

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

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:776
    unscheduleAllWithMinPriority

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

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

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

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

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:889
    pauseAllTargetsWithMinPriority

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:902
    参数列表
    • minPriority Number
    resumeTargets

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:962
    参数列表
    • targetsToResume Array
    pauseTarget

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:981
    参数列表
    • target Object
    resumeTarget

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

    metadescription
    定义于cocos2d/core/CCScheduler.js:1020
    参数列表
    • target Object
    isTargetPaused

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

    metadescription
    返回Boolean
    定义于cocos2d/core/CCScheduler.js:1059
    参数列表
    • target Object