Class cc.Director
- Defined in: CCDirector.js
Constructor Attributes | Constructor Name and Description |
---|---|
ATTENTION: USE cc.director INSTEAD OF cc.Director. |
Method Summary
Class Detail
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 pixel format (default on is RGB565)
- setting the OpenGL buffer depth (default one 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
Field Detail
cc.eventManager.addCustomListener(cc.Director.EVENT_AFTER_DRAW, function(event) { cc.log("after draw event."); });
cc.eventManager.addCustomListener(cc.Director.EVENT_AFTER_UPDATE, function(event) { cc.log("after update event."); });
cc.eventManager.addCustomListener(cc.Director.EVENT_AFTER_VISIT, function(event) { cc.log("after visit event."); });
cc.eventManager.addCustomListener(cc.Director.EVENT_PROJECTION_CHANGED, function(event) { cc.log("Projection changed."); });
Method Detail
-
calculateDeltaTime()calculates delta time since last time it was called
-
{cc.Point} convertToGL(uiPoint)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- Parameters:
- {cc.Point} uiPoint
- Returns:
- {cc.Point}
-
{cc.Point} convertToUI(glPoint)Converts an WebGL coordinate to a view coordinate
Useful to convert node points to window points for calls such as glScissor
Implementation can be found in CCDirectorWebGL- Parameters:
- {cc.Point} glPoint
- Returns:
- {cc.Point}
-
drawScene()Draw the scene. This method is called every frame. Don't call it manually.
-
end()End the life of director in the next frame
-
{cc.ActionManager} getActionManager()Returns the cc.ActionManager associated with this director
- Returns:
- {cc.ActionManager}
-
{Number} getAnimationInterval()Returns the FPS value
- Returns:
- {Number}
-
{Number} getContentScaleFactor()Returns the size in pixels of the surface. It could be different than the screen size.
High-res devices might have a higher surface size than the screen size.- Returns:
- {Number}
-
{cc.DirectorDelegate} getDelegate()Returns the cc.director delegate.
- Returns:
- {cc.DirectorDelegate}
-
{Number} getDeltaTime()Returns the delta time since last frame
- Returns:
- {Number}
-
{cc.Node} getNotificationNode()This object will be visited after the main scene is visited.
This object MUST implement the "visit" selector.
Useful to hook a notification object- Returns:
- {cc.Node}
-
{cc.view} getOpenGLView()Get the CCEGLView, where everything is rendered.
Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js.- Returns:
- {cc.view}
-
{Number} getProjection()Sets an OpenGL projection.
Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js.- Returns:
- {Number}
-
{cc.Scene} getRunningScene()Returns current running Scene. Director can only run one Scene at the time
- Returns:
- {cc.Scene}
-
{cc.Scheduler} getScheduler()Returns the cc.Scheduler associated with this director
- Returns:
- {cc.Scheduler}
-
{Number} getSecondsPerFrame()Returns seconds per frame
- Returns:
- {Number}
-
{Number} getTotalFrames()Returns how many frames were called since the director started
- Returns:
- {Number}
-
{cc.Point} getVisibleOrigin()Returns the visible origin of the running scene
- Returns:
- {cc.Point}
-
{cc.Size} getVisibleSize()Returns the visible size of the running scene
- Returns:
- {cc.Size}
-
{cc.Size} getWinSize()Returns the size of the WebGL view in points.
It takes into account any possible rotation (device orientation) of the window- Returns:
- {cc.Size}
-
{cc.Size} 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.- Returns:
- {cc.Size}
-
{Number} getZEye()Returns the z eye, only available in WebGL mode
- Returns:
- {Number}
-
{Boolean} isDisplayStats()Returns whether or not to display the FPS informations
- Returns:
- {Boolean}
-
{Boolean} isNextDeltaTimeZero()Returns whether next delta time equals to zero
- Returns:
- {Boolean}
-
{Boolean} isPaused()Returns whether or not the Director is paused
- Returns:
- {Boolean}
-
{Boolean} isSendCleanupToScene()Returns whether or not the replaced scene will receive the cleanup message.
If the new scene is pushed, then the old scene won't receive the "cleanup" message.
If the new scene replaces the old one, the it will receive the "cleanup" message.- Returns:
- {Boolean}
-
mainLoop()Run main loop of director
-
pause()Pause the director's ticker
-
popScene()Pops out a scene from the queue.
This scene will replace the running one.
The running scene will be deleted. If there are no more scenes in the stack the execution is terminated.
ONLY call it if there is a running scene. -
popToRootScene()Pops out all scenes from the queue until the root scene in the queue.
This scene will replace the running one.
Internally it will call "popToSceneStackLevel(1)" -
popToSceneStackLevel(level)Pops out all scenes from the queue until it reaches "level".
If level is 0, it will end the director.
If level is 1, it will pop all scenes until it reaches to root scene.
If level is <= than the current stack level, it won't do anything.- Parameters:
- {Number} level
-
purgeCachedData()Removes cached all cocos2d cached data. It will purge the cc.textureCache, cc.spriteFrameCache, cc.animationCache
-
purgeDirector()Purge the cc.director itself, including unschedule all schedule, remove all event listeners, clean up and exit the running scene, stops all animations, clear cached data.
-
pushScene(scene)Suspends the execution of the running scene, pushing it on the stack of suspended scenes.
The new scene will be executed.
Try to avoid big stacks of pushed scenes to reduce memory allocation.
ONLY call it if there is a running scene.- Parameters:
- {cc.Scene} scene
-
resume()Resume director after pause, if the current scene is not paused, nothing will happen.
-
runScene(scene)Run a scene. Replaces the running scene with a new one or enter the first scene.
- Parameters:
- {cc.Scene} scene
-
setActionManager(actionManager)Sets the cc.ActionManager associated with this director
- Parameters:
- {cc.ActionManager} actionManager
-
setAlphaBlending(on)Enables/disables OpenGL alpha blending.
Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js.- Parameters:
- {Boolean} on
-
setAnimationInterval(value)Sets animation interval
- Parameters:
- {Number} value
- the animation interval desired
-
setClearColor(clearColor)set color for clear screen.
Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js- Parameters:
- {cc.color} clearColor
-
setContentScaleFactor(scaleFactor)The size in pixels of the surface. It could be different than the screen size.
High-res devices might have a higher surface size than the screen size.- Parameters:
- {Number} scaleFactor
-
setDefaultValues()Sets the default values based on the CCConfiguration info
-
{cc.DirectorDelegate} setDelegate(delegate)Sets the cc.director delegate. It shall implement the CCDirectorDelegate protocol
- Parameters:
- delegate
- Returns:
- {cc.DirectorDelegate}
-
setDepthTest(on)Enables or disables WebGL depth test.
Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js- Parameters:
- {Boolean} on
-
setDisplayStats(displayStats)Sets whether display the FPS on the bottom-left corner
- Parameters:
- {Boolean} displayStats
-
setNextDeltaTimeZero(nextDeltaTimeZero)Sets whether next delta time equals to zero
- Parameters:
- {Boolean} nextDeltaTimeZero
-
setNextScene()Starts the registered next scene
-
setNotificationNode(node)Sets Notification Node
- Parameters:
- {cc.Node} node
-
setOpenGLView(openGLView)Sets the view, where everything is rendered, do not call this function.
Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js.- Parameters:
- {cc.view} openGLView
-
setProjection(projection)Sets an OpenGL projection.
Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js.- Parameters:
- {Number} projection
-
setScheduler(scheduler)Sets the cc.Scheduler associated with this director
- Parameters:
- {cc.Scheduler} scheduler
-
setViewport()Update the view port.
Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js. -
startAnimation()Starts Animation
-
stopAnimation()Stops animation