cocos2d-x  3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Director Class Referenceabstract

#include <CCDirector.h>

Inheritance diagram for Director:
Ref DisplayLinkDirector

Public Types

enum  Projection { _2D, _3D, CUSTOM, DEFAULT = _3D }
 

Public Member Functions

void pushMatrix (MATRIX_STACK_TYPE type)
void popMatrix (MATRIX_STACK_TYPE type)
void loadIdentityMatrix (MATRIX_STACK_TYPE type)
void loadMatrix (MATRIX_STACK_TYPE type, const Mat4 &mat)
void multiplyMatrix (MATRIX_STACK_TYPE type, const Mat4 &mat)
Mat4 getMatrix (MATRIX_STACK_TYPE type)
void resetMatrixStack ()
 Director (void)
virtual ~Director ()
virtual bool init ()
ScenegetRunningScene ()
 Get current running Scene. More...
 
double getAnimationInterval ()
 Get the FPS value. More...
 
virtual void setAnimationInterval (double interval)=0
 Set the FPS value. More...
 
bool isDisplayStats ()
 Whether or not to display the FPS on the bottom-left corner. More...
 
void setDisplayStats (bool displayStats)
 Display the FPS on the bottom-left corner. More...
 
float getSecondsPerFrame ()
 seconds per frame More...
 
GLViewgetOpenGLView ()
 Get the GLView, where everything is rendered. More...
 
void setOpenGLView (GLView *openGLView)
TextureCachegetTextureCache () const
bool isNextDeltaTimeZero ()
void setNextDeltaTimeZero (bool nextDeltaTimeZero)
bool isPaused ()
 Whether or not the Director is paused. More...
 
unsigned int getTotalFrames ()
 How many frames were called since the director started. More...
 
Projection getProjection ()
 Sets an OpenGL projection. More...
 
void setProjection (Projection projection)
void setViewport ()
 Sets the glViewport. More...
 
bool isSendCleanupToScene ()
 How many frames were called since the director started. More...
 
NodegetNotificationNode () const
 This object will be visited after the main scene is visited. More...
 
void setNotificationNode (Node *node)
const SizegetWinSize () const
 returns the size of the OpenGL view in points. More...
 
Size getWinSizeInPixels () const
 returns the size of the OpenGL view in pixels. More...
 
Size getVisibleSize () const
 returns visible size of the OpenGL view in points. More...
 
Vec2 getVisibleOrigin () const
 returns visible origin of the OpenGL view in points. More...
 
Vec2 convertToGL (const Vec2 &point)
 converts a UIKit coordinate to an OpenGL coordinate Useful to convert (multi) touch coordinates to the current layout (portrait or landscape) More...
 
Vec2 convertToUI (const Vec2 &point)
 converts an OpenGL coordinate to a UIKit coordinate Useful to convert node points to window points for calls such as glScissor More...
 
float getZEye () const
 XXX: missing description. More...
 
void runWithScene (Scene *scene)
 Enters the Director's main loop with the given Scene. More...
 
void pushScene (Scene *scene)
 Suspends the execution of the running scene, pushing it on the stack of suspended scenes. More...
 
void popScene ()
 Pops out a scene from the stack. More...
 
void popToRootScene ()
 Pops out all scenes from the stack until the root scene in the queue. More...
 
void popToSceneStackLevel (int level)
 Pops out all scenes from the stack until it reaches level. More...
 
void replaceScene (Scene *scene)
 Replaces the running scene with a new one. More...
 
void end ()
 Ends the execution, releases the running scene. More...
 
void pause ()
 Pauses the running scene. More...
 
void resume ()
 Resumes the paused scene The scheduled timers will be activated again. More...
 
virtual void stopAnimation ()=0
 Stops the animation. More...
 
virtual void startAnimation ()=0
 The main loop is triggered again. More...
 
void drawScene ()
 Draw the scene. More...
 
void purgeCachedData ()
 Removes all cocos2d cached data. More...
 
void setDefaultValues ()
 sets the default values based on the Configuration info More...
 
void setGLDefaultValues ()
 sets the OpenGL default values More...
 
void setAlphaBlending (bool on)
 enables/disables OpenGL alpha blending More...
 
void setDepthTest (bool on)
 enables/disables OpenGL depth test More...
 
virtual void mainLoop ()=0
void setContentScaleFactor (float scaleFactor)
 The size in pixels of the surface. More...
 
float getContentScaleFactor () const
SchedulergetScheduler () const
 Gets the Scheduler associated with this director. More...
 
void setScheduler (Scheduler *scheduler)
 Sets the Scheduler associated with this director. More...
 
ActionManagergetActionManager () const
 Gets the ActionManager associated with this director. More...
 
void setActionManager (ActionManager *actionManager)
 Sets the ActionManager associated with this director. More...
 
EventDispatchergetEventDispatcher () const
 Gets the EventDispatcher associated with this director. More...
 
void setEventDispatcher (EventDispatcher *dispatcher)
 Sets the EventDispatcher associated with this director. More...
 
RenderergetRenderer () const
 Returns the Renderer. More...
 
float getDeltaTime () const
 Returns the Console. More...
 
float getFrameRate () const
 get Frame Rate More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()

Static Public Member Functions

static DirectorgetInstance ()
 returns a shared instance of the director More...
 
static DirectorsharedDirector ()

Static Public Attributes

static const char * EVENT_PROJECTION_CHANGED
static const char * EVENT_AFTER_UPDATE
static const char * EVENT_AFTER_VISIT
static const char * EVENT_AFTER_DRAW

Protected Member Functions

void initMatrixStack ()
void purgeDirector ()
void setNextScene ()
void showStats ()
void createStatsLabel ()
void calculateMPF ()
void getFPSImageData (unsigned char **datapointer, ssize_t *length)
void calculateDeltaTime ()
 calculates delta time since last time it was called More...
 
void initTextureCache ()
void destroyTextureCache ()
- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 

Protected Attributes

bool _purgeDirectorInNextLoop
Scheduler_scheduler
 Scheduler associated with this director. More...
 
ActionManager_actionManager
 ActionManager associated with this director. More...
 
EventDispatcher_eventDispatcher
 EventDispatcher associated with this director. More...
 
EventCustom_eventProjectionChanged
EventCustom_eventAfterDraw
EventCustom_eventAfterVisit
EventCustom_eventAfterUpdate
float _deltaTime
GLView_openGLView
TextureCache_textureCache
double _animationInterval
double _oldAnimationInterval
bool _landscape
bool _displayStats
float _accumDt
float _frameRate
LabelAtlas_FPSLabel
LabelAtlas_drawnBatchesLabel
LabelAtlas_drawnVerticesLabel
bool _paused
 Whether or not the Director is paused. More...
 
unsigned int _totalFrames
unsigned int _frames
float _secondsPerFrame
Scene_runningScene
Scene_nextScene
bool _sendCleanupToScene
Vector< Scene * > _scenesStack
struct timeval * _lastUpdate
bool _nextDeltaTimeZero
Projection _projection
Size _winSizeInPoints
float _contentScaleFactor
Node_notificationNode
Renderer_renderer
- Protected Attributes inherited from Ref
unsigned int _referenceCount
 count of references More...
 

Friends

class GLViewProtocol

Constructor & Destructor Documentation

Director ( void  )
virtual ~Director ( )
virtual

Member Function Documentation

void calculateDeltaTime ( )
protected

calculates delta time since last time it was called

void calculateMPF ( )
protected
Vec2 convertToGL ( const Vec2 point)

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

Vec2 convertToUI ( const Vec2 point)

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 destroyTextureCache ( )
protected
void drawScene ( )

Draw the scene.

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

void end ( )

Ends the execution, releases the running scene.

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

ActionManager* getActionManager ( ) const
inline

Gets the ActionManager associated with this director.

Since
v2.0
double getAnimationInterval ( )
inline

Get the FPS value.

float getContentScaleFactor ( ) const
inline
float getDeltaTime ( ) const

Returns the Console.

Since
v3.0
EventDispatcher* getEventDispatcher ( ) const
inline

Gets the EventDispatcher associated with this director.

Since
v3.0
void getFPSImageData ( unsigned char **  datapointer,
ssize_t length 
)
protected
float getFrameRate ( ) const
inline

get Frame Rate

static Director* getInstance ( )
static

returns a shared instance of the director

Mat4 getMatrix ( MATRIX_STACK_TYPE  type)
Node* getNotificationNode ( ) const
inline

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 Notifications (http://github.com/manucorporat/CCNotifications)

Since
v0.99.5
GLView* getOpenGLView ( )
inline

Get the GLView, where everything is rendered.

Projection getProjection ( )
inline

Sets an OpenGL projection.

Since
v0.8.2
Renderer* getRenderer ( ) const
inline

Returns the Renderer.

Since
v3.0
Scene* getRunningScene ( )
inline

Get current running Scene.

Director can only run one Scene at a time

Scheduler* getScheduler ( ) const
inline

Gets the Scheduler associated with this director.

Since
v2.0
float getSecondsPerFrame ( )
inline

seconds per frame

TextureCache* getTextureCache ( ) const
unsigned int getTotalFrames ( )
inline

How many frames were called since the director started.

Vec2 getVisibleOrigin ( ) const

returns visible origin of the OpenGL view in points.

Size getVisibleSize ( ) const

returns visible size of the OpenGL view in points.

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

const Size& getWinSize ( ) const

returns the size of the OpenGL view in points.

Size getWinSizeInPixels ( ) const

returns the size of the OpenGL view in pixels.

float getZEye ( ) const

XXX: missing description.

virtual bool init ( )
virtual
void initMatrixStack ( )
protected
void initTextureCache ( )
protected
bool isDisplayStats ( )
inline

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

bool isNextDeltaTimeZero ( )
inline
bool isPaused ( )
inline

Whether or not the Director is paused.

bool isSendCleanupToScene ( )
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
void loadIdentityMatrix ( MATRIX_STACK_TYPE  type)
void loadMatrix ( MATRIX_STACK_TYPE  type,
const Mat4 mat 
)
virtual void mainLoop ( )
pure virtual

Implemented in DisplayLinkDirector.

void multiplyMatrix ( MATRIX_STACK_TYPE  type,
const Mat4 mat 
)
void pause ( )

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 popMatrix ( MATRIX_STACK_TYPE  type)
void popScene ( )

Pops out a scene from the stack.

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 ( )

Pops out all scenes from the stack 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 stack 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 ( )

Removes all cocos2d cached data.

It will purge the TextureCache, SpriteFrameCache, LabelBMFont cache

Since
v0.99.3
void purgeDirector ( )
protected
void pushMatrix ( MATRIX_STACK_TYPE  type)
void pushScene ( Scene 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.

void replaceScene ( Scene scene)

Replaces the running scene with a new one.

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

void resetMatrixStack ( )
void resume ( )

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 ( Scene scene)

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

void setActionManager ( ActionManager actionManager)

Sets the ActionManager associated with this director.

Since
v2.0
void setAlphaBlending ( bool  on)

enables/disables OpenGL alpha blending

virtual void setAnimationInterval ( double  interval)
pure virtual

Set the FPS value.

Implemented in DisplayLinkDirector.

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 ( )

sets the default values based on the Configuration info

void setDepthTest ( bool  on)

enables/disables OpenGL depth test

void setDisplayStats ( bool  displayStats)
inline

Display the FPS on the bottom-left corner.

void setEventDispatcher ( EventDispatcher dispatcher)

Sets the EventDispatcher associated with this director.

Since
v3.0
void setGLDefaultValues ( )

sets the OpenGL default values

void setNextDeltaTimeZero ( bool  nextDeltaTimeZero)
void setNextScene ( )
protected
void setNotificationNode ( Node node)
void setOpenGLView ( GLView openGLView)
void setProjection ( Projection  projection)
void setScheduler ( Scheduler scheduler)

Sets the Scheduler associated with this director.

Since
v2.0
void setViewport ( )

Sets the glViewport.

static Director* sharedDirector ( )
inlinestatic
void showStats ( )
protected
virtual void startAnimation ( )
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 DisplayLinkDirector.

virtual void stopAnimation ( )
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 DisplayLinkDirector.

Friends And Related Function Documentation

friend class GLViewProtocol
friend

Member Data Documentation

float _accumDt
protected
ActionManager* _actionManager
protected

ActionManager associated with this director.

Since
v2.0
double _animationInterval
protected
float _contentScaleFactor
protected
float _deltaTime
protected
bool _displayStats
protected
LabelAtlas* _drawnBatchesLabel
protected
LabelAtlas* _drawnVerticesLabel
protected
EventCustom * _eventAfterDraw
protected
EventCustom * _eventAfterUpdate
protected
EventCustom * _eventAfterVisit
protected
EventDispatcher* _eventDispatcher
protected

EventDispatcher associated with this director.

Since
v3.0
EventCustom*
_eventProjectionChanged
protected
LabelAtlas* _FPSLabel
protected
float _frameRate
protected
unsigned int _frames
protected
bool _landscape
protected
struct timeval* _lastUpdate
protected
bool _nextDeltaTimeZero
protected
Scene* _nextScene
protected
Node* _notificationNode
protected
double _oldAnimationInterval
protected
GLView* _openGLView
protected
bool _paused
protected

Whether or not the Director is paused.

Projection _projection
protected
bool _purgeDirectorInNextLoop
protected
Renderer* _renderer
protected
Scene* _runningScene
protected
Vector<Scene*> _scenesStack
protected
Scheduler* _scheduler
protected

Scheduler associated with this director.

Since
v2.0
float _secondsPerFrame
protected
bool _sendCleanupToScene
protected
TextureCache* _textureCache
protected
unsigned int _totalFrames
protected
Size _winSizeInPoints
protected
const char* EVENT_AFTER_DRAW
static
const char* EVENT_AFTER_UPDATE
static
const char* EVENT_AFTER_VISIT
static
const char*
EVENT_PROJECTION_CHANGED
static

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