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

  • any
    • Director

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

Events

Static Readonly EVENT_AFTER_DRAW

EVENT_AFTER_DRAW: "director_after_draw" = "director_after_draw"
en

The event which will be triggered after the rendering process.

zh

渲染过程之后所触发的事件。

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_BEFORE_COMMIT

EVENT_BEFORE_COMMIT: "director_before_commit" = "director_before_commit"
en

The event which will be triggered before the pipeline render commit.

zh

当前渲染帧提交前所触发的事件。

Static Readonly EVENT_BEFORE_DRAW

EVENT_BEFORE_DRAW: "director_before_draw" = "director_before_draw"
en

The event which will be triggered before the rendering process.

zh

渲染过程之前所触发的事件。

Static Readonly EVENT_BEFORE_PHYSICS

EVENT_BEFORE_PHYSICS: "director_before_physics" = "director_before_physics"

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

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 _startTime

_startTime: number

Private _systems

_systems: System[]

Private _totalFrames

_totalFrames: number

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_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

Private init

  • _init(): Promise<void>

Private initOnRendererInitialized

  • _initOnRendererInitialized(): void

calculateDeltaTime

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

    Parameters

    • now: any

    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

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

getTotalTime

  • getTotalTime(): 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

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

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

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

    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

    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

unregisterSystem

  • unregisterSystem(sys: System): void

Generated using TypeDoc