Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Director

ATTENTION: USE `director` INSTEAD OF `Director`.
`director` is a singleton object which manage your game's logic flow.
Since the `director` is a singleton, you don't need to call any constructor or create functions,
the standard way to use it is by calling:
- `director.methodName();`

It creates and handle the main Window and manages how and when to execute the Scenes.

The director is also responsible for:
- initializing the OpenGL context
- setting the OpenGL pixel format (default on is RGB565)
- setting the OpenGL buffer depth (default on is 0-bit)
- setting the color for clear screen (default one is BLACK)
- setting the projection (default one is 3D)
- setting the orientation (default one is Portrait)


The director also sets the default OpenGL context:
- GL_TEXTURE_2D is enabled
- GL_VERTEX_ARRAY is enabled
- GL_COLOR_ARRAY is enabled
- GL_TEXTURE_COORD_ARRAY is enabled

`director` also synchronizes timers with the refresh rate of the display.
Features and Limitations:
- Scheduled timers & drawing are synchronizes with the refresh rate of the display
- Only supports animation intervals of 1/60 1/30 & 1/15

Hierarchy

Index

Type aliases

Static OnBeforeLoadScene

OnBeforeLoadScene: () => void

Type declaration

    • (): void
    • Returns void

Static OnLoadSceneProgress

OnLoadSceneProgress: (completedCount: number, totalCount: number, item: any) => void
param

The number of the items that are already completed.

param

The total number of the items.

param

The latest item which flow out the pipeline.

Type declaration

    • (completedCount: number, totalCount: number, item: any): void
    • Parameters

      • completedCount: number
      • totalCount: number
      • item: any

      Returns void

Static OnSceneLaunched

OnSceneLaunched: (error: null | Error, scene?: Scene) => void

Type declaration

    • (error: null | Error, scene?: Scene): void
    • Parameters

      • error: null | Error
      • Optional scene: Scene

      Returns void

Static OnSceneLoaded

OnSceneLoaded: (error: null | Error, sceneAsset?: SceneAsset) => void

Type declaration

    • (error: null | Error, sceneAsset?: SceneAsset): void
    • Parameters

      • error: null | Error
      • Optional sceneAsset: SceneAsset

      Returns void

Static OnUnload

OnUnload: () => void

Type declaration

    • (): void
    • Returns void

Constructors

constructor

Properties

_compScheduler

_compScheduler: ComponentScheduler

Private _deltaTime

_deltaTime: number

Private _invalid

_invalid: boolean

Private _lastUpdate

_lastUpdate: number

Private _loadingScene

_loadingScene: string

_nodeActivator

_nodeActivator: NodeActivator

Private _paused

_paused: boolean

Private _purgeDirectorInNextLoop

_purgeDirectorInNextLoop: boolean

Private _root

_root: Root | null

Private _scene

_scene: Scene | null

Private _scheduler

_scheduler: Scheduler

Private _systems

_systems: System[]

Private _totalFrames

_totalFrames: number

Static Readonly EVENT_AFTER_DRAW

EVENT_AFTER_DRAW: "director_after_draw" = "director_after_draw"

The event which will be triggered after the rendering process.

Static Readonly EVENT_AFTER_PHYSICS

EVENT_AFTER_PHYSICS: "director_after_physics" = "director_after_physics"

The event which will be triggered after the physics process.
物理过程之后所触发的事件。

Static Readonly EVENT_AFTER_SCENE_LAUNCH

EVENT_AFTER_SCENE_LAUNCH: "director_after_scene_launch" = "director_after_scene_launch"

The event which will be triggered after launching a new scene.

Static Readonly EVENT_AFTER_UPDATE

EVENT_AFTER_UPDATE: "director_after_update" = "director_after_update"

The event which will be triggered after engine and components update logic.

Static Readonly EVENT_BEFORE_DRAW

EVENT_BEFORE_DRAW: "director_before_draw" = "director_before_draw"

The event which will be triggered before the rendering process.

Static Readonly EVENT_BEFORE_PHYSICS

EVENT_BEFORE_PHYSICS: "director_before_physics" = "director_before_physics"

The event which will be triggered before the physics process.
物理过程之前所触发的事件。

Static Readonly EVENT_BEFORE_SCENE_LAUNCH

EVENT_BEFORE_SCENE_LAUNCH: "director_before_scene_launch" = "director_before_scene_launch"

The event which will be triggered before launching a new scene.

Static Readonly EVENT_BEFORE_SCENE_LOADING

EVENT_BEFORE_SCENE_LOADING: "director_before_scene_loading" = "director_before_scene_loading"

The event which will be triggered before loading a new scene.

Static Readonly EVENT_BEFORE_UPDATE

EVENT_BEFORE_UPDATE: "director_before_update" = "director_before_update"

The event which will be triggered at the beginning of every frame.

Static Readonly EVENT_INIT

EVENT_INIT: "director_init" = "director_init"

The event which will be triggered when the singleton of Director initialized.

Static Readonly EVENT_RESET

EVENT_RESET: "director_reset" = "director_reset"

The event which will be triggered when the singleton of Director reset.

Static instance

instance: Director

Accessors

root

  • get root(): null | Root

Methods

getSceneUuid

  • getSceneUuid(key: string | number): any

Private init

  • _init(): boolean

Private initOnRendererInitialized

  • _initOnRendererInitialized(): void

Private loadSceneByUuid

  • loadSceneByUuid(uuid: string, doNotRun?: undefined | false | true): void
  • loadSceneByUuid(uuid: string, onLaunched?: OnSceneLaunched, doNotRun?: undefined | false | true): void
  • loadSceneByUuid(uuid: string, onLaunched?: OnSceneLaunched, onUnloaded?: OnUnload, doNotRun?: undefined | false | true): void
  • Loads the scene by its uuid.

    Parameters

    • uuid: string

      场景资源的 uuid。

    • Optional doNotRun: undefined | false | true

      仅加载和初始化场景,但并不运行。此参数仅在编辑器环境中生效。

    Returns void

  • Parameters

    • uuid: string
    • Optional onLaunched: OnSceneLaunched
    • Optional doNotRun: undefined | false | true

    Returns void

  • Parameters

    • uuid: string
    • Optional onLaunched: OnSceneLaunched
    • Optional onUnloaded: OnUnload
    • Optional doNotRun: undefined | false | true

    Returns void

calculateDeltaTime

  • calculateDeltaTime(): void
  • Calculates delta time since last time it was called, the result is saved to an internal property.

    Returns void

convertToGL

  • Converts a view coordinate to an WebGL coordinate
    Useful to convert (multi) touches coordinates to the current layout (portrait or landscape)
    Implementation can be found in directorWebGL.

    deprecated

    since v2.0

    Parameters

    Returns Vec2

convertToUI

  • Converts an OpenGL coordinate to a view coordinate
    Useful to convert node points to window points for calls such as glScissor
    Implementation can be found in directorWebGL.

    deprecated

    since v2.0

    Parameters

    Returns Vec2

emit

  • emit(type: EventType, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any): void
  • Trigger an event directly with the event name and necessary arguments.

    Parameters

    • type: EventType

      event type

    • Optional arg0: any
    • Optional arg1: any
    • Optional arg2: any
    • Optional arg3: any
    • Optional arg4: any

    Returns void

end

  • end(): void

getAnimationInterval

  • getAnimationInterval(): number

getAnimationManager

  • getAnimationManager(): any
  • Returns the AnimationManager associated with this director. Please use getSystem(AnimationManager.ID)

    deprecated

    Returns any

getCurrentTime

  • getCurrentTime(): number

getDeltaTime

  • getDeltaTime(): number

getRunningScene

  • getRunningScene(): null | Scene

getScene

  • getScene(): Scene | null
  • Returns current logic Scene.

    example
    import { director } from 'cc';
    // This will help you to get the Canvas node in scene
    director.getScene().getChildByName('Canvas');

    Returns Scene | null

getScheduler

getSystem

  • getSystem(name: string): undefined | System

getTotalFrames

  • getTotalFrames(): number

getWinSize

  • getWinSize(): Size
  • Returns the size of the WebGL view in points.
    It takes into account any possible rotation (device orientation) of the window.

    deprecated

    since v2.0

    Returns Size

getWinSizeInPixels

  • getWinSizeInPixels(): Size
  • Returns the size of the OpenGL view in pixels.
    It takes into account any possible rotation (device orientation) of the window.
    On Mac winSize and winSizeInPixels return the same value. (The pixel here refers to the resource resolution. If you want to get the physics resolution of device, you need to use view.getFrameSize())

    deprecated

    since v2.0

    Returns Size

hasEventListener

  • hasEventListener(type: string, callback?: Function, target?: undefined | object): boolean
  • Checks whether there is correspond event listener registered on the given event.

    Parameters

    • type: string

      Event type.

    • Optional callback: Function

      Callback function when event triggered.

    • Optional target: undefined | object

      Callback callee.

    Returns boolean

isPaused

  • isPaused(): boolean

loadScene

  • Loads the scene by its name.

    Parameters

    • sceneName: string

      The name of the scene to load.

    • Optional onLaunched: OnSceneLaunched

      callback, will be called after scene launched.

    • Optional onUnloaded: OnUnload

    Returns boolean

    if error, return false

mainLoop

  • mainLoop(time: number): void

off

  • Removes the listeners previously registered with the same type, callback, target and or useCapture, if only type is passed as parameter, all listeners registered with that type will be removed.

    example

    import { log } from 'cc'; // register fire eventListener var callback = eventTarget.on('fire', function () { log("fire in the hole"); }, target); // remove fire event listener eventTarget.off('fire', callback, target); // remove all fire event listeners eventTarget.off('fire');

    Type parameters

    • TFunction: Function

    Parameters

    • type: EventType

      A string representing the event type being removed.

    • Optional callback: TFunction

      The callback to remove.

    • Optional thisArg: any

    Returns void

on

  • on<TFunction>(type: EventType, callback: TFunction, thisArg?: any, once?: undefined | false | true): typeof callback
  • Register an callback of a specific event type on the EventTarget. This type of event should be triggered via emit.

    example

    import { log } from 'cc'; eventTarget.on('fire', function () { log("fire in the hole"); }, node);

    Type parameters

    • TFunction: Function

    Parameters

    • type: EventType

      A string representing the event type to listen for.

    • callback: TFunction

      The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

    • Optional thisArg: any

      The target (this object) to invoke the callback, can be null

    • Optional once: undefined | false | true

    Returns typeof callback

    • Just returns the incoming callback so you can save the anonymous function easier.

once

  • once<TFunction>(type: EventType, callback: TFunction, thisArg?: any): typeof callback
  • Register an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.

    example

    import { log } from 'cc'; eventTarget.once('fire', function () { log("this is the callback and will be invoked only once"); }, node);

    Type parameters

    • TFunction: Function

    Parameters

    • type: EventType

      A string representing the event type to listen for.

    • callback: TFunction

      The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

    • Optional thisArg: any

    Returns typeof callback

pause

  • pause(): void
  • Pause the director's ticker, only involve the game logic execution.
    It won't pause the rendering process nor the event manager.
    If you want to pause the entire game including rendering, audio and event,
    please use game.pause.

    Returns void

preloadScene

  • Pre-loads the scene to reduces loading time. You can call this method at any time you want.
    After calling this method, you still need to launch the scene by director.loadScene.
    It will be totally fine to call director.loadScene at any time even if the preloading is not
    yet finished, the scene will be launched after loaded automatically.

    Parameters

    • sceneName: string

      场景名称。

    • Optional onLoaded: OnSceneLoaded

      加载回调。

    Returns void

  • Pre-loads the scene to reduces loading time. You can call this method at any time you want.
    After calling this method, you still need to launch the scene by director.loadScene.
    It will be totally fine to call director.loadScene at any time even if the preloading is not
    yet finished, the scene will be launched after loaded automatically.

    Parameters

    Returns void

purgeCachedData

  • purgeCachedData(): void

purgeDirector

  • purgeDirector(): void
  • Purge the director itself, including unschedule all schedule,
    remove all event listeners, clean up and exit the running scene, stops all animations, clear cached data.

    Returns void

registerSystem

  • registerSystem(name: string, sys: System, priority: number): void

removeAll

  • removeAll(typeOrTarget: string | object): void
  • Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

    Parameters

    • typeOrTarget: string | object

      The event type or target with which the listeners will be removed

    Returns void

reset

  • reset(): void

resume

  • resume(): void
  • Resume game logic execution after pause, if the current scene is not paused, nothing will happen.

    Returns void

Private runScene

  • Run a scene. Replaces the running scene with a new one or enter the first scene.
    The new scene will be launched at the end of the current frame.

    Parameters

    • scene: Scene

      The need run scene.

    • Optional onBeforeLoadScene: OnBeforeLoadScene

      The function invoked at the scene before loading.

    • Optional onLaunched: OnSceneLaunched

      The function invoked at the scene after launch.

    Returns void

runSceneImmediate

  • Run a scene. Replaces the running scene with a new one or enter the first scene.
    The new scene will be launched immediately.

    Parameters

    • scene: Scene

      The need run scene.

    • Optional onBeforeLoadScene: OnBeforeLoadScene

      The function invoked at the scene before loading.

    • Optional onLaunched: OnSceneLaunched

      The function invoked at the scene after launch.

    Returns void

setAnimationInterval

  • setAnimationInterval(value: number): void
  • Sets animation interval, this doesn't control the main loop.
    To control the game's frame rate overall, please use game.setFrameRate

    deprecated

    since v2.0

    Parameters

    • value: number

      The animation interval desired.

    Returns void

setClearColor

  • setClearColor(clearColor: Color): void
  • Set color for clear screen.
    (Implementation can be found in directorCanvas.js/directorWebGL.js)

    deprecated

    since v2.0

    Parameters

    Returns void

setDepthTest

  • setDepthTest(value: boolean): void
  • Enables or disables WebGL depth test.
    Implementation can be found in directorCanvas.js/directorWebGL.js

    deprecated

    since v2.0

    Parameters

    • value: boolean

    Returns void

setScheduler

startAnimation

  • startAnimation(): void

stopAnimation

  • stopAnimation(): void

targetOff

  • targetOff(typeOrTarget: string | object): void
  • Removes all callbacks previously registered with the same target (passed as parameter). This is not for removing all listeners in the current event target, and this is not for removing all listeners the target parameter have registered. It's only for removing all listeners (callback and target couple) registered on the current event target by the target parameter.

    Parameters

    • typeOrTarget: string | object

      The target to be searched for all related listeners

    Returns void

unregisterSystem

  • unregisterSystem(sys: System): void

Generated using TypeDoc