Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Scheduler

Scheduler 是负责触发回调函数的类。
通常情况下,建议使用 director.getScheduler() 来获取系统定时器。
有两种不同类型的定时器:
- update 定时器:每一帧都会触发。您可以自定义优先级。
- 自定义定时器:自定义定时器可以每一帧或者自定义的时间间隔触发。
如果希望每帧都触发,应该使用 update 定时器,使用 update 定时器更快,而且消耗更少的内存。

Hierarchy

  • System
    • Scheduler

Implements

Index

Constructors

constructor

Properties

Private _arrayForTimers

_arrayForTimers: any

Private _currentTarget

_currentTarget: any

Private _currentTargetSalvaged

_currentTargetSalvaged: boolean

Protected _executeInEditMode

_executeInEditMode: boolean = false

Private _hashForTimers

_hashForTimers: any

Private _hashForUpdates

_hashForUpdates: any

Protected _id

_id: string = ""

Protected _priority

_priority: number = 0

Private _timeScale

_timeScale: number

Private _updateHashLocked

_updateHashLocked: boolean

Private _updates0List

_updates0List: any[]

Private _updatesNegList

_updatesNegList: any[]

Private _updatesPosList

_updatesPosList: any[]

Static ID

ID: string = "scheduler"

Static PRIORITY_NON_SYSTEM

PRIORITY_NON_SYSTEM: number = Scheduler.PRIORITY_SYSTEM + 1

用户调度最低优先级。

Static PRIORITY_SYSTEM

PRIORITY_SYSTEM: number = 1 << 31

系统服务的优先级。

Accessors

id

  • get id(): string
  • set id(id: string): void

priority

  • get priority(): number
  • set priority(value: number): void

Methods

Private appendIn

  • appendIn(ppList: any, listElement: any): void

Private priorityIn

  • priorityIn(ppList: any, listElement: any, priority: any): void

Private removeHashElement

  • removeHashElement(element: any): void

Private removeUpdateFromHash

  • removeUpdateFromHash(entry: any): void

getTimeScale

  • getTimeScale(): number

init

  • init(): void

isScheduled

  • isScheduled(callback: any, target: ISchedulable): undefined | false | true
  • 检查指定的回调函数和回调对象组合是否存在定时器。

    Parameters

    • callback: any

      The callback to check.

    • target: ISchedulable

      The target of the callback.

    Returns undefined | false | true

    True if the specified callback is invoked, false if not.

isTargetPaused

pauseAllTargets

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

    Returns any

pauseAllTargetsWithMinPriority

  • pauseAllTargetsWithMinPriority(minPriority: number): any
  • 暂停所有优先级的值大于指定优先级的定时器。
    你应该只暂停优先级的值大于 PRIORITY_NON_SYSTEM_MIN 的定时器。

    Parameters

    • minPriority: number

    Returns any

pauseTarget

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

    Parameters

    Returns void

postUpdate

  • postUpdate(dt: number): void

resumeTarget

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

    Parameters

    Returns void

resumeTargets

  • resumeTargets(targetsToResume: any): void
  • 恢复指定数组中所有对象的定时器。
    这个函数是 pauseAllCallbacks 的逆操作。

    Parameters

    • targetsToResume: any

    Returns void

schedule

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

    Parameters

    • callback: Function
    • target: ISchedulable
    • interval: number
    • Optional repeat: undefined | number
    • Optional delay: undefined | number
    • Optional paused: undefined | false | true

    Returns void

scheduleUpdate

  • scheduleUpdate(target: ISchedulable, priority: number, paused: boolean): void
  • 使用指定的优先级为指定的对象设置 update 定时器。
    update 定时器每一帧都会被触发,触发时自动调用指定对象的 "update" 函数。
    优先级的值越低,定时器被触发的越早。

    Parameters

    Returns void

setTimeScale

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

    Parameters

    • timeScale: any

    Returns void

unschedule

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

    Parameters

    • callback: any

      The callback to be unscheduled

    • target: ISchedulable

      The target bound to the callback.

    Returns void

unscheduleAll

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

    Returns void

unscheduleAllForTarget

  • unscheduleAllForTarget(target: any): void
  • 取消指定对象的所有定时器,包括 update 定时器。

    Parameters

    • target: any

      The target to be unscheduled.

    Returns void

unscheduleAllWithMinPriority

  • unscheduleAllWithMinPriority(minPriority: number): void
  • 取消所有优先级的值大于指定优先级的定时器。
    你应该只取消优先级的值大于 PRIORITY_NON_SYSTEM_MIN 的定时器。

    Parameters

    • minPriority: number

      The minimum priority of selector to be unscheduled. Which means, all selectors which priority is higher than minPriority will be unscheduled.

    Returns void

unscheduleUpdate

update

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

    Parameters

    • dt: any

      delta time

    Returns void

Static enableForTarget

  • 任何需要用 Scheduler 管理任务的对象主体都应该调用这个方法,并且应该在调用任何 Scheduler API 之前调用这个方法。 这个方法会给对象添加一个 id 属性,如果这个属性不存在的话。

    Parameters

    Returns void

Static sortByPriority

  • sortByPriority(a: System, b: System): 1 | -1 | 0

Generated using TypeDoc