CCDirector Class Reference
| Inherits from | CC_VIEWCONTROLLER |
| Declared in | CCDirector.h |
Overview
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 ES 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)
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
Tasks
-
runningThreadproperty -
runningSceneproperty -
animationIntervalproperty -
displayStatsproperty -
nextDeltaTimeZeroproperty -
pausedproperty -
animatingproperty -
projectionproperty -
totalFramesproperty -
secondsPerFrameproperty -
responderManagerproperty -
delegateproperty -
contentScaleFactorproperty -
UIScaleFactorproperty -
designSizeproperty -
projectionMatrixproperty -
globalShaderUniformsproperty -
+ sharedDirector -
– viewSize -
– viewSizeInPixels -
– reshapeProjection: -
– convertToGL: -
– convertToUI: -
– presentScene: -
– presentScene:withTransition: -
– runWithScene: -
– pushScene: -
– popScene -
– popToRootScene -
– popToRootSceneWithTransition: -
– replaceScene: -
– replaceScene:withTransition: -
– pushScene:withTransition: -
– popSceneWithTransition: -
– end -
– pause -
– resume -
– stopAnimation -
– startAnimation -
– view -
– purgeCachedData
Properties
UIScaleFactor
UI scaling factor, default value is 1. Positions and content sizes are scale by this factor if the position type is set to scale.
@property (nonatomic, readwrite, assign) float UIScaleFactorDeclared In
CCDirector.hanimating
Whether or not the Director is active (animating)
@property (nonatomic, readonly, getter=isAnimating) BOOL animatingDeclared In
CCDirector.hanimationInterval
The FPS value
@property (nonatomic, readwrite, assign) CCTime animationIntervalDeclared In
CCDirector.hcontentScaleFactor
Content scaling factor. Sets the ratio of Cocos2D “points” to pixels. Default value is initalized from the content scale of the GL view used by the director.
@property (nonatomic, assign) CGFloat contentScaleFactorDeclared In
CCDirector.hdelegate
CCDirector delegate. It shall implement the CCDirectorDelegate protocol
@property (nonatomic, readwrite, weak) id<CCDirectorDelegate> delegateDeclared In
CCDirector.hdesignSize
User definable value that is used for default contentSizes of many node types (CCScene, CCNodeColor, etc). Defaults to the view size.
@property (nonatomic, assign) CGSize designSizeDeclared In
CCDirector.hdisplayStats
Whether or not to display director statistics
@property (nonatomic, readwrite, assign) BOOL displayStatsDeclared In
CCDirector.hglobalShaderUniforms
The current global shader values values.
@property (nonatomic, readonly) NSMutableDictionary *globalShaderUniformsDeclared In
CCDirector.hnextDeltaTimeZero
whether or not the next delta time will be zero
@property (nonatomic, readwrite, assign, getter=isNextDeltaTimeZero) BOOL nextDeltaTimeZeroDeclared In
CCDirector.hpaused
Whether or not the Director is paused
@property (nonatomic, readonly, getter=isPaused) BOOL pausedDeclared In
CCDirector.hprojection
Sets an OpenGL projection
@property (nonatomic, readwrite) CCDirectorProjection projectionDeclared In
CCDirector.hprojectionMatrix
Projection matrix used for rendering.
@property (nonatomic, readonly) GLKMatrix4 projectionMatrixDeclared In
CCDirector.hresponderManager
Sets the touch manager
@property (nonatomic, strong) CCResponderManager *responderManagerDeclared In
CCDirector.hrunningScene
The current running Scene. Director can only run one Scene at the time
@property (nonatomic, readonly) CCScene *runningSceneDeclared In
CCDirector.hrunningThread
returns the cocos2d thread. If you want to run any cocos2d task, run it in this thread. Typically this is the main thread.
@property (weak, readonly, nonatomic) NSThread *runningThreadDeclared In
CCDirector.hInstance Methods
convertToGL:
Converts a UIKit coordinate to an OpenGL coordinate.
- (CGPoint)convertToGL:(CGPoint)pParameters
- p
Point to convert.
Return Value
Converted point.
Discussion
Useful to convert (multi) touch coordinates to the current layout (portrait or landscape).
Declared In
CCDirector.hconvertToUI:
Converts an OpenGL coordinate to a UIKit coordinate.
- (CGPoint)convertToUI:(CGPoint)pParameters
- p
Point to convert.
Return Value
Converted point.
Discussion
Useful to convert node points to window points for calls such as glScissor.
Declared In
CCDirector.hend
Ends the execution, releases the running scene. It doesn’t remove the OpenGL view from its parent. You have to do it manually.
- (void)endDeclared In
CCDirector.hpause
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)pauseDeclared In
CCDirector.hpopScene
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)popSceneDeclared In
CCDirector.hpopSceneWithTransition:
Replaces the running scene, with the last scene pushed to the stack, using a transition
- (void)popSceneWithTransition:(CCTransition *)transitionParameters
- transition
The transition to use
Declared In
CCDirector.hpopToRootScene
Pops out all scenes from the queue until the root scene in the queue.
- (void)popToRootSceneDiscussion
This scene will replace the running one.
Internally it will call popToSceneStackLevel:1
Declared In
CCDirector.hpopToRootSceneWithTransition:
Pops out all scenes from the queue until the root scene in the queue, using a transition
- (void)popToRootSceneWithTransition:(CCTransition *)transitionDiscussion
This scene will replace the running one.
Internally it will call popToRootScene
Declared In
CCDirector.hpresentScene:
Presents a new scene.
- (void)presentScene:(CCScene *)sceneParameters
- scene
Scene to start.
Discussion
If no scene is currently running, the scene will be started.
If another scene is currently running, this scene will be stopped, and the new scene started.
Declared In
CCDirector.hpresentScene:withTransition:
Presents a new scene, with a transition.
- (void)presentScene:(CCScene *)scene withTransition:(CCTransition *)transitionParameters
- scene
Scene to start.
- transition
Transition to use.
Discussion
If no scene is currently running, the new scene will be started without a transition.
If another scene is currently running, this scene will be stopped, and the new scene started, according to the provided transition.
Declared In
CCDirector.hpurgeCachedData
Removes all the cocos2d data that was cached automatically. It will purge the CCTextureCache, CCLabelBMFont cache. IMPORTANT: The CCSpriteFrameCache won’t be purged. If you want to purge it, you have to purge it manually.
- (void)purgeCachedDataDeclared In
CCDirector.hpushScene:
Suspends the execution of the running scene, pushing it on the stack of suspended scenes.
- (void)pushScene:(CCScene *)sceneParameters
- scene
New scene to start.
Discussion
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.
Declared In
CCDirector.hpushScene:withTransition:
Pushes the running scene onto the scene stack, and presents the incoming scene, using a transition
- (void)pushScene:(CCScene *)scene withTransition:(CCTransition *)transitionParameters
- scene
The scene to present
- transition
The transition to use
Declared In
CCDirector.hreplaceScene:
Replaces the running scene with a new one. The running scene is terminated.
- (void)replaceScene:(CCScene *)sceneParameters
- scene
New scene to start.
Discussion
ONLY call it if there is a running scene.
Declared In
CCDirector.hreplaceScene:withTransition:
Presents a new scene by either starting first scene, or replacing the running Performs a transition between the outgoing and the incoming scene
- (void)replaceScene:(CCScene *)scene withTransition:(CCTransition *)transitionParameters
- scene
The incoming scene
- transition
The transition to perform
Declared In
CCDirector.hreshapeProjection:
Changes the projection size.
- (void)reshapeProjection:(CGSize)newViewSizeParameters
- newViewSize
New projection size.
Declared In
CCDirector.hresume
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)resumeDeclared In
CCDirector.hrunWithScene:
Enters the Director’s main loop with the given Scene.
- (void)runWithScene:(CCScene *)sceneParameters
- scene
Scene to run.
Discussion
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
Declared In
CCDirector.hstartAnimation
The main loop is triggered again. Call this function only if [stopAnimation] was called earlier
- (void)startAnimationDiscussion
Warning: Don’t call this function to start the main loop. To run the main loop call runWithScene
Declared In
CCDirector.hstopAnimation
Stops the animation. Nothing will be drawn. The main loop won’t be triggered anymore. If you want to pause your animation call [pause] instead.
- (void)stopAnimationDeclared In
CCDirector.hviewSizeInPixels
returns the size of the OpenGL view in pixels. On Mac winSize and winSizeInPixels return the same value.
- (CGSize)viewSizeInPixelsDeclared In
CCDirector.h