Namespace cc.director

cc.director is a singleton of DisplayLinkDirector type director.
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 projection (default one is 3D)
- setting the orientation (default one is Protrait)


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

With DisplayLinkDirector functionality, cc.director 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

Method Summary

Method Detail

  • calculateDeltaTime()
    calculates delta time since last time it was called
  • {cc.Point} convertToGL(uiPoint)

    converts a UIKit coordinate to an OpenGL coordinate
    Useful to convert (multi) touches coordinates to the current layout (portrait or landscape)

    Parameters:
    {cc.Point} uiPoint
    Returns:
    {cc.Point}
  • {cc.Point} convertToUI(glPoint)

    converts an OpenGL coordinate to a UIKit coordinate
    Useful to convert node points to window points for calls such as glScissor

    Parameters:
    {cc.Point} glPoint
    Returns:
    {cc.Point}
  • drawScene()
    Draw the scene. This method is called every frame. Don't call it manually.
  • end()
    end director
  • {Number} getAnimationInterval()
    Get the FPS value
    Returns:
    {Number}
  • {Number} getContentScaleFactor()

    get 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.
    Only available when compiled using SDK >= 4.0.

    Returns:
    {Number}
  • {cc.DirectorDelegate} getDelegate()
    CCDirector delegate. It shall implemente the CCDirectorDelegate protocol
    Returns:
    {cc.DirectorDelegate}
  • {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, like CCNotifications (http://github.com/manucorporat/CCNotifications)

    Returns:
    {cc.Node}
  • {*} getOpenGLView()
    Get the CCEGLView, where everything is rendered
    Returns:
    {*}
  • {Number} getProjection()
    Sets an OpenGL projection
    Returns:
    {Number}
  • {cc.Scene} getRunningScene()
    Get current running Scene. Director can only run one Scene at the time
    Returns:
    {cc.Scene}
  • getScheduler()
    (cc.Scheduler associated with this director)
  • {Number} getSecondsPerFrame()
    seconds per frame
    Returns:
    {Number}
  • {Number} getTotalFrames()
    How many frames were called since the director started
    Returns:
    {Number}
  • {cc.Size} getWinSize()

    returns the size of the OpenGL 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}
  • {Boolean} init()
    initializes cc.director
    Returns:
    {Boolean}
  • {Boolean} isDisplayStats()
    Whether or not to display the FPS on the bottom-left corner
    Returns:
    {Boolean}
  • {Boolean} isNextDeltaTimeZero()
    is next delta time zero
    Returns:
    {Boolean}
  • {Boolean} isPaused()
    Whether or not the Director is paused
    Returns:
    {Boolean}
  • {Boolean} isSendCleanupToScene()

    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()
    main loop of director
  • pause()
    pause director
  • 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 Director
  • 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
  • runScene(scene)
    Run a scene. Replaces the running scene with a new one when the scene is running.
    Parameters:
    {cc.Scene} scene
  • setAlphaBlending(on)
    enables/disables OpenGL alpha blending
    Parameters:
    {Boolean} on
  • setAnimationInterval(value)
    set Animation Interval
    Parameters:
    {Number} value
  • 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.
    Only available when compiled using SDK >= 4.0.

    Parameters:
    {Number} scaleFactor
  • setDefaultValues()
    sets the default values based on the CCConfiguration info
  • setDepthTest(on)
    enables/disables OpenGL depth test
    Parameters:
    {Boolean} on
  • setDisplayStats(displayStats)
    Display the FPS on the bottom-left corner
    Parameters:
    {Boolean} displayStats
  • setGLDefaultValues()
    sets the OpenGL default values
  • setNextDeltaTimeZero(nextDeltaTimeZero)
    set next delta time is zero
    Parameters:
    {Boolean} nextDeltaTimeZero
  • setNextScene()
    set next scene
  • setNotificationNode(node)
    set Notification Node
    Parameters:
    {cc.Node} node
  • setOpenGLView(openGLView)
    Set the CCEGLView, where everything is rendered
    Parameters:
    {*} openGLView
  • setProjection(projection)
    Sets an OpenGL projection
    Parameters:
    {Number} projection
  • setViewport()
    Sets the glViewport
  • startAnimation()
    start Animation
  • stopAnimation()
    stop animation