Director Class

Extends EventTarget

Module: cc

ATTENTION: USE cc.director INSTEAD OF cc.Director.
cc.director is a singleton object which manage your game's logic flow.
Since the cc.director is a singleton, you don't need to call any constructor or create functions,
the standard way to use it is by calling:
- cc.director.methodName();
It creates and handle the main Window and manages how and when to execute the Scenes.

The cc.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 cc.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

cc.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

Index

Properties
  • EVENT_PROJECTION_CHANGED String The event projection changed of cc.Director.
  • EVENT_BEFORE_SCENE_LOADING String The event which will be triggered before loading a new scene.
  • EVENT_BEFORE_SCENE_LAUNCH String The event which will be triggered before launching a new scene.
  • EVENT_AFTER_SCENE_LAUNCH String The event which will be triggered after launching a new scene.
  • EVENT_BEFORE_UPDATE String The event which will be triggered at the beginning of every frame.
  • EVENT_AFTER_UPDATE String The event which will be triggered after engine and components update logic.
  • EVENT_BEFORE_VISIT String The event is deprecated since v2.0, please use cc.Director.EVENT_BEFORE_DRAW instead
  • EVENT_AFTER_VISIT String The event is deprecated since v2.0, please use cc.Director.EVENT_BEFORE_DRAW instead
  • EVENT_BEFORE_DRAW String The event which will be triggered before the rendering process.
  • EVENT_AFTER_DRAW String The event which will be triggered after the rendering process.
  • PROJECTION_2D Number Constant for 2D projection (orthogonal projection)
  • PROJECTION_3D Number Constant for 3D projection with a fovy=60, znear=0.5f and zfar=1500.
  • PROJECTION_CUSTOM Number Constant for custom projection, if cc.Director's projection set to it, it calls "updateProjection" on the projection delegate.
  • PROJECTION_DEFAULT Number Constant for default projection of cc.Director, default projection is 2D projection
Methods
  • convertToGL Converts a view coordinate to an WebGL coordinate...
  • convertToUI Converts an OpenGL coordinate to a view coordinate...
  • end End the life of director in the next frame
  • getWinSize Returns the size of the WebGL view in points....
  • getWinSizeInPixels On Mac winSize and winSizeInPixels return the same value.
  • pause Pause the director's ticker, only involve the game logic execution.
  • runSceneImmediate Run a scene.
  • runScene Run a scene.
  • loadScene Loads the scene by its name.
  • preloadScene Preloads the scene to reduces loading time.
  • resume Resume game logic execution after pause, if the current scene is not paused, nothing will happen.
  • setDepthTest Enables or disables WebGL depth test....
  • setClearColor Set color for clear screen....
  • getRunningScene Returns current logic Scene.
  • getScene Returns current logic Scene.
  • getAnimationInterval Returns the FPS value.
  • setAnimationInterval Sets animation interval, this doesn't control the main loop.
  • getDeltaTime Returns the delta time since last frame.
  • getTotalTime Returns the total passed time since game start, unit: ms
  • getTotalFrames Returns how many frames were called since the director started.
  • isPaused Returns whether or not the Director is paused.
  • getScheduler Returns the cc.Scheduler associated with this director.
  • setScheduler Sets the cc.Scheduler associated with this director.
  • getActionManager Returns the cc.ActionManager associated with this director.
  • setActionManager Sets the cc.ActionManager associated with this director.
  • getCollisionManager Returns the cc.CollisionManager associated with this director.
  • getPhysicsManager Returns the cc.PhysicsManager associated with this director.
  • getPhysics3DManager Returns the cc.Physics3DManager associated with this director.
  • hasEventListener Checks whether the EventTarget object has any callback registered for a specific type of event.
  • on Register an callback of a specific event type on the EventTarget.
  • off Removes the listeners previously registered with the same type, callback, target and or useCapture,...
  • targetOff Removes all callbacks previously registered with the same target (passed as parameter).
  • once Register an callback of a specific event type on the EventTarget,...
  • dispatchEvent Send an event with the event object.
  • clear Destroy all callbackInfos.
  • removeAll Removes all callbacks registered in a certain event type or all callbacks registered with a certain target
  • emit Trigger an event directly with the event name and necessary arguments.
Events

Details

Properties

EVENT_PROJECTION_CHANGED

The event projection changed of cc.Director. This event will not get triggered since v2.0

meta description
Type String
Defined in cocos2d/core/CCDirector.js:930
Deprecated since v2.0
EVENT_BEFORE_SCENE_LOADING

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

meta description
Type String
Defined in cocos2d/core/CCDirector.js:946
EVENT_BEFORE_SCENE_LAUNCH

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

meta description
Type String
Defined in cocos2d/core/CCDirector.js:961
EVENT_AFTER_SCENE_LAUNCH

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

meta description
Type String
Defined in cocos2d/core/CCDirector.js:976
EVENT_BEFORE_UPDATE

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

meta description
Type String
Defined in cocos2d/core/CCDirector.js:990
EVENT_AFTER_UPDATE

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

meta description
Type String
Defined in cocos2d/core/CCDirector.js:1004
EVENT_BEFORE_VISIT

The event is deprecated since v2.0, please use cc.Director.EVENT_BEFORE_DRAW instead

meta description
Type String
Defined in cocos2d/core/CCDirector.js:1013
Deprecated since v2.0
EVENT_AFTER_VISIT

The event is deprecated since v2.0, please use cc.Director.EVENT_BEFORE_DRAW instead

meta description
Type String
Defined in cocos2d/core/CCDirector.js:1023
Deprecated since v2.0
EVENT_BEFORE_DRAW

The event which will be triggered before the rendering process.

meta description
Type String
Defined in cocos2d/core/CCDirector.js:1038
EVENT_AFTER_DRAW

The event which will be triggered after the rendering process.

meta description
Type String
Defined in cocos2d/core/CCDirector.js:1052
PROJECTION_2D

Constant for 2D projection (orthogonal projection)

meta description
Type Number
Defined in cocos2d/core/CCDirector.js:1063
Deprecated since v2.0
PROJECTION_3D

Constant for 3D projection with a fovy=60, znear=0.5f and zfar=1500.

meta description
Type Number
Defined in cocos2d/core/CCDirector.js:1073
Deprecated since v2.0
PROJECTION_CUSTOM

Constant for custom projection, if cc.Director's projection set to it, it calls "updateProjection" on the projection delegate.

meta description
Type Number
Defined in cocos2d/core/CCDirector.js:1083
Deprecated since v2.0
PROJECTION_DEFAULT

Constant for default projection of cc.Director, default projection is 2D projection

meta description
Type Number
Defined in cocos2d/core/CCDirector.js:1093
Deprecated since v2.0

Methods

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 CCDirectorWebGL.

meta description
Returns Vec2
Defined in cocos2d/core/CCDirector.js:241
Deprecated since v2.0
Parameters
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 CCDirectorWebGL.

meta description
Returns Vec2
Defined in cocos2d/core/CCDirector.js:263
Deprecated since v2.0
Parameters
end

End the life of director in the next frame

meta description
Defined in cocos2d/core/CCDirector.js:292
getWinSize

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

meta description
Returns Size
Defined in cocos2d/core/CCDirector.js:300
Deprecated since v2.0
getWinSizeInPixels

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 cc.view.getFrameSize())

meta description
Returns Size
Defined in cocos2d/core/CCDirector.js:313
Deprecated since v2.0
pause

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 entier game including rendering, audio and event, please use Game.pause

meta description
Defined in cocos2d/core/CCDirector.js:330
runSceneImmediate

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

meta description
Defined in cocos2d/core/CCDirector.js:415
Parameters
  • scene Scene | SceneAsset The need run scene.
  • onBeforeLoadScene Function The function invoked at the scene before loading.
  • onLaunched Function The function invoked at the scene after launch.
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.

meta description
Defined in cocos2d/core/CCDirector.js:495
Parameters
  • scene Scene | SceneAsset The need run scene.
  • onBeforeLoadScene Function The function invoked at the scene before loading.
  • onLaunched Function The function invoked at the scene after launch.
loadScene

Loads the scene by its name.

meta description
Returns Boolean
Defined in cocos2d/core/CCDirector.js:519
Parameters
  • sceneName String The name of the scene to load.
  • onLaunched Function callback, will be called after scene launched.
preloadScene

Preloads 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 cc.director.loadScene. It will be totally fine to call cc.director.loadScene at any time even if the preloading is not yet finished, the scene will be launched after loaded automatically.

meta description
Defined in cocos2d/core/CCDirector.js:561
Parameters
  • sceneName String The name of the scene to preload.
  • onProgress Function callback, will be called when the load progression change.
    • completedCount Number The number of the items that are already completed
    • totalCount Number The total number of the items
    • item Object The latest item which flow out the pipeline
  • onLoaded Function callback, will be called after scene loaded.
    • error Error null or the error object.
resume

Resume game logic execution after pause, if the current scene is not paused, nothing will happen.

meta description
Defined in cocos2d/core/CCDirector.js:594
setDepthTest

Enables or disables WebGL depth test.
Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js

meta description
Defined in cocos2d/core/CCDirector.js:613
Deprecated since v2.0
Parameters
setClearColor

Set color for clear screen.
(Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js)

meta description
Defined in cocos2d/core/CCDirector.js:629
Deprecated since v2.0
Parameters
getRunningScene

Returns current logic Scene.

meta description
Returns Scene
Defined in cocos2d/core/CCDirector.js:647
Deprecated since v2.0
getScene

Returns current logic Scene.

meta description
Returns Scene
Defined in cocos2d/core/CCDirector.js:659
Examples
// This will help you to get the Canvas node in scene
 cc.director.getScene().getChildByName('Canvas');
getAnimationInterval

Returns the FPS value. Please use Game.setFrameRate to control animation interval.

meta description
Returns Number
Defined in cocos2d/core/CCDirector.js:672
Deprecated since v2.0
setAnimationInterval

Sets animation interval, this doesn't control the main loop. To control the game's frame rate overall, please use Game.setFrameRate

meta description
Defined in cocos2d/core/CCDirector.js:683
Deprecated since v2.0
Parameters
  • value Number The animation interval desired.
getDeltaTime

Returns the delta time since last frame.

meta description
Returns Number
Defined in cocos2d/core/CCDirector.js:694
getTotalTime

Returns the total passed time since game start, unit: ms

meta description
Returns Number
Defined in cocos2d/core/CCDirector.js:704
getTotalFrames

Returns how many frames were called since the director started.

meta description
Returns Number
Defined in cocos2d/core/CCDirector.js:714
isPaused

Returns whether or not the Director is paused.

meta description
Returns Boolean
Defined in cocos2d/core/CCDirector.js:724
getScheduler

Returns the cc.Scheduler associated with this director.

meta description
Returns Scheduler
Defined in cocos2d/core/CCDirector.js:734
setScheduler

Sets the cc.Scheduler associated with this director.

meta description
Defined in cocos2d/core/CCDirector.js:744
Parameters
getActionManager

Returns the cc.ActionManager associated with this director.

meta description
Returns ActionManager
Defined in cocos2d/core/CCDirector.js:756
setActionManager

Sets the cc.ActionManager associated with this director.

meta description
Defined in cocos2d/core/CCDirector.js:765
Parameters
getCollisionManager

Returns the cc.CollisionManager associated with this director.

meta description
Returns CollisionManager
Defined in cocos2d/core/CCDirector.js:791
getPhysicsManager

Returns the cc.PhysicsManager associated with this director.

meta description
Returns PhysicsManager
Defined in cocos2d/core/CCDirector.js:801
getPhysics3DManager

Returns the cc.Physics3DManager associated with this director.

meta description
Returns Physics3DManager
Defined in cocos2d/core/CCDirector.js:811
hasEventListener

Checks whether the EventTarget object has any callback registered for a specific type of event.

meta description
Returns Boolean
Defined in cocos2d/core/event/event-target.js:69
Parameters
  • type String The type of event.
on

Register an callback of a specific event type on the EventTarget. This type of event should be triggered via emit.

meta description
Returns Function
Defined in cocos2d/core/event/event-target.js:77
Parameters
  • type String A string representing the event type to listen for.
  • callback Function The callback that will be invoked when the event is dispatched.
                           The callback is ignored if it is a duplicate (the callbacks are unique).
    
    • arg1 Any arg1
    • arg2 Any arg2
    • arg3 Any arg3
    • arg4 Any arg4
    • arg5 Any arg5
  • target Object The target (this object) to invoke the callback, can be null
Examples
eventTarget.on('fire', function () {
    cc.log("fire in the hole");
}, node);
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.

meta description
Defined in cocos2d/core/event/event-target.js:119
Parameters
  • type String A string representing the event type being removed.
  • callback Function The callback to remove.
  • target Object The target (this object) to invoke the callback, if it's not given, only callback without target will be removed
Examples
// register fire eventListener
var callback = eventTarget.on('fire', function () {
    cc.log("fire in the hole");
}, target);
// remove fire event listener
eventTarget.off('fire', callback, target);
// remove all fire event listeners
eventTarget.off('fire');
targetOff

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.

meta description
Defined in cocos2d/core/event/event-target.js:163
Parameters
  • target Object The target to be searched for all related listeners
once

Register an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.

meta description
Defined in cocos2d/core/event/event-target.js:182
Parameters
  • type String A string representing the event type to listen for.
  • callback Function The callback that will be invoked when the event is dispatched.
                           The callback is ignored if it is a duplicate (the callbacks are unique).
    
    • arg1 Any arg1
    • arg2 Any arg2
    • arg3 Any arg3
    • arg4 Any arg4
    • arg5 Any arg5
  • target Object The target (this object) to invoke the callback, can be null
Examples
eventTarget.once('fire', function () {
    cc.log("this is the callback and will be invoked only once");
}, node);
dispatchEvent

Send an event with the event object.

meta description
Defined in cocos2d/core/event/event-target.js:208
Parameters
clear

Destroy all callbackInfos.

meta description
Defined in cocos2d/core/event/event-target.js:221
removeAll

Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

meta description
Defined in cocos2d/core/platform/callbacks-invoker.js:235
Parameters
  • keyOrTarget String | Object The event key to be removed or the target to be removed
emit

Trigger an event directly with the event name and necessary arguments.

meta description
Defined in cocos2d/core/platform/callbacks-invoker.js:309
Parameters
  • key String event type
  • arg1 Any First argument
  • arg2 Any Second argument
  • arg3 Any Third argument
  • arg4 Any Fourth argument
  • arg5 Any Fifth argument
Examples
eventTarget.emit('fire', event);
eventTarget.emit('fire', message, emitter);

Events

cc.Director.EVENT_BEFORE_SCENE_LOADING Event

Module: cc

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

Index

Details

cc.Director.EVENT_AFTER_SCENE_LAUNCH Event

Module: cc

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

Index

Details

cc.Director.EVENT_BEFORE_UPDATE Event

Module: cc

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

Index

Details

cc.Director.EVENT_AFTER_UPDATE Event

Module: cc

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

Index

Details

cc.Director.EVENT_BEFORE_DRAW Event

Module: cc

The event which will be triggered before the rendering process.

Index

Details

cc.Director.EVENT_AFTER_DRAW Event

Module: cc

The event which will be triggered after the rendering process.

Index

Details

Director.EVENT_BEFORE_PHYSICS Event

Module: cc

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

Index

Details

Director.EVENT_AFTER_PHYSICS Event

Module: cc

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

Index

Details

results matching ""

    No results matching ""