Cocos Creator API

1.4.x

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

Director

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

Methods

convertToUI
(
  • glPoint
)
Vec2

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.

name type description
glPoint Vec2

returns:

type: Vec2

getWinSize ( ) Size

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

returns:

type: Size

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.

returns:

type: Size

getVisibleSize ( ) Size

Returns the visible size of the running scene.

returns:

type: Size

getVisibleOrigin ( ) Vec2

Returns the visible origin of the running scene.

returns:

type: Vec2

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

runSceneImmediate
(
  • scene
  • [onBeforeLoadScene ]
  • [onLaunched ]
)

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

name type description
scene Scene

The need run scene.

onBeforeLoadScene optional Function

The function invoked at the scene before loading.

onLaunched optional Function

The function invoked at the scene after launch.

runScene
(
  • scene
  • [onBeforeLoadScene ]
  • [onLaunched ]
)
private

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.

name type description
scene Scene

The need run scene.

onBeforeLoadScene optional Function

The function invoked at the scene before loading.

onLaunched optional Function

The function invoked at the scene after launch.

loadScene
(
  • sceneName
  • [onLaunched ]
)
Boolean

Loads the scene by its name.

name type description
sceneName String

The name of the scene to load.