cocos2d-x  2.2
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CCDirector Class Referenceabstract

Class that creates and handle the main Window and manages how and when to execute the Scenes. More...

#include <CCDirector.h>

Inheritance diagram for CCDirector:
CCObject TypeInfo CCCopying CCDisplayLinkDirector

Public Member Functions

 CCDirector (void)
virtual ~CCDirector (void)
virtual bool init (void)
virtual long getClassTypeInfo ()
CCScenegetRunningScene (void)
 Get current running Scene. More...
 
double getAnimationInterval (void)
 Get the FPS value. More...
 
virtual void setAnimationInterval (double dValue)=0
 Set the FPS value. More...
 
bool isDisplayStats (void)
 Whether or not to display the FPS on the bottom-left corner. More...
 
void setDisplayStats (bool bDisplayStats)
 Display the FPS on the bottom-left corner. More...
 
float getSecondsPerFrame ()
 seconds per frame More...
 
CCEGLViewgetOpenGLView (void)
 Get the CCEGLView, where everything is rendered. More...
 
void setOpenGLView (CCEGLView *pobOpenGLView)
bool isNextDeltaTimeZero (void)
void setNextDeltaTimeZero (bool bNextDeltaTimeZero)
bool isPaused (void)
 Whether or not the Director is paused. More...
 
unsigned int getTotalFrames (void)
 How many frames were called since the director started. More...
 
ccDirectorProjection getProjection (void)
 Sets an OpenGL projection. More...
 
void setProjection (ccDirectorProjection kProjection)
void reshapeProjection (const CCSize &newWindowSize)
 reshape projection matrix when canvas has been change" More...
 
void setViewport ()
 Sets the glViewport. More...
 
bool isSendCleanupToScene (void)
 How many frames were called since the director started. More...
 
CCNodegetNotificationNode ()
 This object will be visited after the main scene is visited. More...
 
void setNotificationNode (CCNode *node)
CCDirectorDelegategetDelegate () const
 CCDirector delegate. More...
 
void setDelegate (CCDirectorDelegate *pDelegate)
CCSize getWinSize (void)
 returns the size of the OpenGL view in points. More...
 
CCSize getWinSizeInPixels (void)
 returns the size of the OpenGL view in pixels. More...
 
CCSize getVisibleSize ()
 returns visible size of the OpenGL view in points. More...
 
CCPoint getVisibleOrigin ()
 returns visible origin of the OpenGL view in points. More...
 
CCPoint convertToGL (const CCPoint &obPoint)
 converts a UIKit coordinate to an OpenGL coordinate Useful to convert (multi) touch coordinates to the current layout (portrait or landscape) More...
 
CCPoint convertToUI (const CCPoint &obPoint)
 converts an OpenGL coordinate to a UIKit coordinate Useful to convert node points to window points for calls such as glScissor More...
 
float getZEye (void)
 XXX: missing description. More...
 
void runWithScene (CCScene *pScene)
 Enters the Director's main loop with the given Scene. More...
 
void pushScene (CCScene *pScene)
 Suspends the execution of the running scene, pushing it on the stack of suspended scenes. More...
 
void popScene (void)
 Pops out a scene from the queue. More...
 
void popToRootScene (void)
 Pops out all scenes from the queue until the root scene in the queue. More...
 
void popToSceneStackLevel (int level)
 Pops out all scenes from the queue until it reaches level. More...
 
void replaceScene (CCScene *pScene)
 Replaces the running scene with a new one. More...
 
void end (void)
 Ends the execution, releases the running scene. More...
 
void pause (void)
 Pauses the running scene. More...
 
void resume (void)
 Resumes the paused scene The scheduled timers will be activated again. More...
 
virtual void stopAnimation (void)=0
 Stops the animation. More...
 
virtual void startAnimation (void)=0
 The main loop is triggered again. More...
 
void drawScene (void)
 Draw the scene. More...
 
void purgeCachedData (void)
 Removes cached all cocos2d cached data. More...
 
void setDefaultValues (void)
 sets the default values based on the CCConfiguration info More...
 
void setGLDefaultValues (void)
 sets the OpenGL default values More...
 
void setAlphaBlending (bool bOn)
 enables/disables OpenGL alpha blending More...
 
void setDepthTest (bool bOn)
 enables/disables OpenGL depth test More...
 
virtual void mainLoop (void)=0
void setContentScaleFactor (float scaleFactor)
 The size in pixels of the surface. More...
 
float getContentScaleFactor (void)
virtual CCSchedulergetScheduler (void)
 getScheduler More...
 
virtual void setScheduler (CCScheduler *var)
 setScheduler More...
 
virtual CCActionManagergetActionManager (void)
 getActionManager More...
 
virtual void setActionManager (CCActionManager *var)
 setActionManager More...
 
virtual CCTouchDispatchergetTouchDispatcher (void)
 getTouchDispatcher More...
 
virtual void setTouchDispatcher (CCTouchDispatcher *var)
 setTouchDispatcher More...
 
virtual CCKeypadDispatchergetKeypadDispatcher (void)
 getKeypadDispatcher More...
 
virtual void setKeypadDispatcher (CCKeypadDispatcher *var)
 setKeypadDispatcher More...
 
virtual CCAccelerometergetAccelerometer (void)
virtual void setAccelerometer (CCAccelerometer *var)
 setAccelerometer More...
 
virtual float getDeltaTime (void)
 getDeltaTime More...
 
- Public Member Functions inherited from CCObject
 CCObject (void)
virtual ~CCObject (void)
void release (void)
void retain (void)
CCObjectautorelease (void)
CCObjectcopy (void)
bool isSingleReference (void) const
unsigned int retainCount (void) const
virtual bool isEqual (const CCObject *pObject)
virtual void acceptVisitor (CCDataVisitor &visitor)
virtual void update (float dt)
- Public Member Functions inherited from CCCopying
virtual CCObjectcopyWithZone (CCZone *pZone)

Static Public Member Functions

static CCDirectorsharedDirector (void)
 returns a shared instance of the director More...
 

Protected Member Functions

void purgeDirector ()
void setNextScene (void)
void showStats ()
void createStatsLabel ()
void calculateMPF ()
void getFPSImageData (unsigned char **datapointer, unsigned int *length)
void calculateDeltaTime ()
 calculates delta time since last time it was called More...
 

Protected Attributes

CCSchedulerm_pScheduler
 CCScheduler associated with this director. More...
 
CCActionManagerm_pActionManager
 CCActionManager associated with this director. More...
 
CCTouchDispatcherm_pTouchDispatcher
 CCTouchDispatcher associated with this director. More...
 
CCKeypadDispatcherm_pKeypadDispatcher
 CCKeypadDispatcher associated with this director. More...
 
CCAccelerometerm_pAccelerometer
 CCAccelerometer associated with this director. More...
 
float m_fDeltaTime
bool m_bPurgeDirecotorInNextLoop
CCEGLViewm_pobOpenGLView
double m_dAnimationInterval
double m_dOldAnimationInterval
bool m_bLandscape
bool m_bDisplayStats
float m_fAccumDt
float m_fFrameRate
CCLabelAtlasm_pFPSLabel
CCLabelAtlasm_pSPFLabel
CCLabelAtlasm_pDrawsLabel
bool m_bPaused
 Whether or not the Director is paused. More...
 
unsigned int m_uTotalFrames
unsigned int m_uFrames
float m_fSecondsPerFrame
CCScenem_pRunningScene
CCScenem_pNextScene
bool m_bSendCleanupToScene
CCArraym_pobScenesStack
struct cc_timevalm_pLastUpdate
bool m_bNextDeltaTimeZero
ccDirectorProjection m_eProjection
CCSize m_obWinSizeInPoints
float m_fContentScaleFactor
char * m_pszFPS
CCNodem_pNotificationNode
CCDirectorDelegatem_pProjectionDelegate
- Protected Attributes inherited from CCObject
unsigned int m_uReference
unsigned int m_uAutoReleaseCount

Friends

class CCEGLViewProtocol

Additional Inherited Members

- Public Attributes inherited from CCObject
unsigned int m_uID
int m_nLuaID

Detailed Description

Class that creates and handle the main Window and manages how and when to execute the Scenes.

The CCDirector is also responsible for:

  • initializing the OpenGL context
  • 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 Portrait)

Since the CCDirector is a singleton, the standard way to use it is by calling: _ CCDirector::sharedDirector()->methodName();

The CCDirector 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

Constructor & Destructor Documentation

CCDirector ( void  )
virtual ~CCDirector ( void  )
virtual

Member Function Documentation

void calculateDeltaTime ( )
protected

calculates delta time since last time it was called

void calculateMPF ( )
protected
CCPoint convertToGL ( const CCPoint obPoint)

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

CCPoint convertToUI ( const CCPoint obPoint)

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

void createStatsLabel ( )
protected
void drawScene ( void  )

Draw the scene.

This method is called every frame. Don't call it manually.

void end ( void  )

Ends the execution, releases the running scene.

It doesn't remove the OpenGL view from its parent. You have to do it manually.

virtual CCAccelerometer*
getAccelerometer
( void  )
virtual
virtual CCActionManager*
getActionManager
( void  )
virtual

getActionManager

double getAnimationInterval ( void  )
inline

Get the FPS value.

virtual long getClassTypeInfo ( )
inlinevirtual

Implements TypeInfo.

float getContentScaleFactor ( void  )
CCDirectorDelegate* getDelegate ( ) const

CCDirector delegate.

It shall implemente the CCDirectorDelegate protocol

Since
v0.99.5
virtual float getDeltaTime ( void  )
virtual

getDeltaTime

void getFPSImageData ( unsigned char **  datapointer,
unsigned int *  length 
)
protected
virtual CCKeypadDispatcher*
getKeypadDispatcher
( void  )
virtual

getKeypadDispatcher

CCNode* 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)

Since
v0.99.5
CCEGLView* getOpenGLView ( void  )
inline

Get the CCEGLView, where everything is rendered.

ccDirectorProjection getProjection ( void  )
inline

Sets an OpenGL projection.

Since
v0.8.2
CCScene* getRunningScene ( void  )
inline

Get current running Scene.

Director can only run one Scene at the time

virtual CCScheduler* getScheduler ( void  )
virtual

getScheduler

float getSecondsPerFrame ( )
inline

seconds per frame

unsigned int getTotalFrames ( void  )
inline

How many frames were called since the director started.

virtual CCTouchDispatcher*
getTouchDispatcher
( void  )
virtual

getTouchDispatcher

CCPoint getVisibleOrigin ( )

returns visible origin of the OpenGL view in points.

CCSize getVisibleSize ( )

returns visible size of the OpenGL view in points.

the value is equal to getWinSize if don't invoke CCEGLView::setDesignResolutionSize()

CCSize getWinSize ( void  )

returns the size of the OpenGL view in points.

CCSize getWinSizeInPixels ( void  )

returns the size of the OpenGL view in pixels.

float getZEye ( void  )

XXX: missing description.

virtual bool init ( void  )
virtual
bool isDisplayStats ( void  )
inline

Whether or not to display the FPS on the bottom-left corner.

bool isNextDeltaTimeZero ( void  )
inline
bool isPaused ( void  )
inline

Whether or not the Director is paused.

bool isSendCleanupToScene ( void  )
inline

How many frames were called since the director started.

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.

Since
v0.99.0
virtual void mainLoop ( void  )
pure virtual

Implemented in CCDisplayLinkDirector.

void pause ( void  )

Pauses the running scene.

The running scene will be drawed but all scheduled timers will be paused While paused, the draw rate will be 4 FPS to reduce CPU consumption

void popScene ( void  )

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.

void popToRootScene ( void  )

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)

void popToSceneStackLevel ( int  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.

void purgeCachedData ( void  )

Removes cached all cocos2d cached data.

It will purge the CCTextureCache, CCSpriteFrameCache, CCLabelBMFont cache

Since
v0.99.3
void purgeDirector ( )
protected
void pushScene ( CCScene pScene)

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.

void replaceScene ( CCScene pScene)

Replaces the running scene with a new one.

The running scene is terminated. ONLY call it if there is a running scene.

void reshapeProjection ( const CCSize newWindowSize)

reshape projection matrix when canvas has been change"

void resume ( void  )

Resumes the paused scene The scheduled timers will be activated again.

The "delta time" will be 0 (as if the game wasn't paused)

void runWithScene ( CCScene pScene)

Enters the Director's main loop with the given Scene.

Call it to run only your FIRST scene. Don't call it if there is already a running scene.

It will call pushScene: and then it will call startAnimation

virtual void setAccelerometer ( CCAccelerometer var)
virtual

setAccelerometer

virtual void setActionManager ( CCActionManager var)
virtual

setActionManager

void setAlphaBlending ( bool  bOn)

enables/disables OpenGL alpha blending

virtual void setAnimationInterval ( double  dValue)
pure virtual

Set the FPS value.

Implemented in CCDisplayLinkDirector.

void setContentScaleFactor ( float  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.

Since
v0.99.4
void setDefaultValues ( void  )

sets the default values based on the CCConfiguration info

void setDelegate ( CCDirectorDelegate pDelegate)
void setDepthTest ( bool  bOn)

enables/disables OpenGL depth test

void setDisplayStats ( bool  bDisplayStats)
inline

Display the FPS on the bottom-left corner.

void setGLDefaultValues ( void  )

sets the OpenGL default values

virtual void setKeypadDispatcher ( CCKeypadDispatcher var)
virtual

setKeypadDispatcher

void setNextDeltaTimeZero ( bool  bNextDeltaTimeZero)
void setNextScene ( void  )
protected
void setNotificationNode ( CCNode node)
void setOpenGLView ( CCEGLView pobOpenGLView)
void setProjection ( ccDirectorProjection  kProjection)
virtual void setScheduler ( CCScheduler var)
virtual

setScheduler

virtual void setTouchDispatcher ( CCTouchDispatcher var)
virtual

setTouchDispatcher

void setViewport ( )

Sets the glViewport.

static CCDirector* sharedDirector ( void  )
static

returns a shared instance of the director

void showStats ( )
protected
virtual void startAnimation ( void  )
pure virtual

The main loop is triggered again.

Call this function only if [stopAnimation] was called earlier

Warning
Don't call this function to start the main loop. To run the main loop call runWithScene

Implemented in CCDisplayLinkDirector.

virtual void stopAnimation ( void  )
pure virtual

Stops the animation.

Nothing will be drawn. The main loop won't be triggered anymore. If you don't want to pause your animation call [pause] instead.

Implemented in CCDisplayLinkDirector.

Friends And Related Function Documentation

friend class CCEGLViewProtocol
friend

Member Data Documentation

bool m_bDisplayStats
protected
bool m_bLandscape
protected
bool m_bNextDeltaTimeZero
protected
bool m_bPaused
protected

Whether or not the Director is paused.

bool m_bPurgeDirecotorInNextLoop
protected
bool m_bSendCleanupToScene
protected
double m_dAnimationInterval
protected
double m_dOldAnimationInterval
protected
ccDirectorProjection m_eProjection
protected
float m_fAccumDt
protected
float m_fContentScaleFactor
protected
float m_fDeltaTime
protected
float m_fFrameRate
protected
float m_fSecondsPerFrame
protected
CCSize m_obWinSizeInPoints
protected
CCAccelerometer* m_pAccelerometer
protected

CCAccelerometer associated with this director.

Since
v2.0
CCActionManager* m_pActionManager
protected

CCActionManager associated with this director.

Since
v2.0
CCLabelAtlas* m_pDrawsLabel
protected
CCLabelAtlas* m_pFPSLabel
protected
CCKeypadDispatcher*
m_pKeypadDispatcher
protected

CCKeypadDispatcher associated with this director.

Since
v2.0
struct cc_timeval* m_pLastUpdate
protected
CCScene* m_pNextScene
protected
CCNode* m_pNotificationNode
protected
CCEGLView* m_pobOpenGLView
protected
CCArray* m_pobScenesStack
protected
CCDirectorDelegate*
m_pProjectionDelegate
protected
CCScene* m_pRunningScene
protected
CCScheduler* m_pScheduler
protected

CCScheduler associated with this director.

Since
v2.0
CCLabelAtlas* m_pSPFLabel
protected
char* m_pszFPS
protected
CCTouchDispatcher*
m_pTouchDispatcher
protected

CCTouchDispatcher associated with this director.

Since
v2.0
unsigned int m_uFrames
protected
unsigned int m_uTotalFrames
protected

The documentation for this class was generated from the following file: