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
extends CCDirector CCDirector extensions for iPhone
If the window is resized, it will be autoscaled (default behavior)
Tasks
Other Methods
-
runningThreadreturns the cocos2d thread. If you want to run any cocos2d task, run it in this thread. On iOS usually it is the main thread.
property -
runningSceneThe current running Scene. Director can only run one Scene at the time
property -
animationIntervalThe FPS value
property -
displayStatsWhether or not to display director statistics
property -
nextDeltaTimeZerowhether or not the next delta time will be zero
property -
pausedWhether or not the Director is paused
property -
isAnimatingWhether or not the Director is active (animating)
property -
projectionSets an OpenGL projection
property -
totalFramesHow many frames were called since the director started
property -
secondsPerFrameseconds per frame
property -
sendCleanupToSceneWhether 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.
property -
notificationNodeThis 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)
property -
delegateCCDirector delegate. It shall implement the CCDirectorDelegate protocol
property -
schedulerCCScheduler associated with this director
property -
actionManagerCCActionManager associated with this director
property -
+ sharedDirectorreturns a shared instance of the director
-
– winSizereturns the size of the OpenGL view in points
-
– winSizeInPixelsreturns the size of the OpenGL view in pixels. On Mac winSize and winSizeInPixels return the same value.
-
– reshapeProjection:changes the projection size
-
– setViewportSets the glViewport
-
– convertToGL:converts a UIKit coordinate to an OpenGL coordinate Useful to convert (multi) touch coordinates to the current layout (portrait or landscape)
-
– convertToUI:converts an OpenGL coordinate to a UIKit coordinate Useful to convert node points to window points for calls such as glScissor
-
– getZEyeXXX: missing description
-
– runWithScene: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.
-
– pushScene: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.
-
– popScenePops 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.
-
– popToRootScenePops out all scenes from the queue until the root scene in 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.
-
– replaceScene:Replaces the running scene with a new one. The running scene is terminated. ONLY call it if there is a running scene.
-
– endEnds the execution, releases the running scene. It doesn’t remove the OpenGL view from its parent. You have to do it manually.
-
– pausePauses 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
-
– resumeResumes the paused scene The scheduled timers will be activated again. The “delta time” will be 0 (as if the game wasn’t paused)
-
– stopAnimationStops the animation. Nothing will be drawn. The main loop won’t be triggered anymore. If you want to pause your animation call [pause] instead.
-
– startAnimationThe main loop is triggered again. Call this function only if [stopAnimation] was called earlier
-
– drawSceneDraw the scene. This method is called every frame. Don’t call it manually.
-
– setView:sets the openGL view
-
– viewreturns the OpenGL view
-
– purgeCachedDataRemoves 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.
-
– setGLDefaultValuessets the OpenGL default values
-
– setAlphaBlending:enables/disables OpenGL alpha blending
-
– setDepthTest:enables/disables OpenGL depth test
-
– createStatsLabelcreates the Stats labels
Other Methods
-
displayFPSWhether or not to display the FPS on the bottom-left corner
property -
openGLViewThe EAGLView, where everything is rendered
property -
pixelFormatPixel format used to create the context
property -
deviceOrientationThe device orientattion
property -
contentScaleFactorThe 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. In non High-res device the contentScale will be emulated.
property -
+ setDirectorType:There are 4 types of Director. – kCCDirectorTypeNSTimer (default) – kCCDirectorTypeMainLoop – kCCDirectorTypeThreadMainLoop – kCCDirectorTypeDisplayLink
-
– setPixelFormat:Uses a new pixel format for the EAGLView. Call this class method before attaching it to a UIView Default pixel format: kRGB565. Supported pixel formats: kRGBA8 and kRGB565 (Deprecated: Set the pixel format when creating the EAGLView. This method will be removed in v1.0)
-
– setDepthBufferFormat:Change depth buffer format of the render buffer. Call this class method before attaching it to a UIWindow/UIView Default depth buffer: 0 (none). Supported: kCCDepthBufferNone, kCCDepthBuffer16, and kCCDepthBuffer24 (Deprecated: Set the depth buffer format when creating the EAGLView. This method will be removed in v1.0)
-
– detachdetach the cocos2d view from the view/window
-
– attachInWindow:attach in UIWindow using the full frame. It will create a EAGLView. (Deprecated: set setOpenGLView instead. Will be removed in v1.0)
-
– attachInView:attach in UIView using the full frame. It will create a EAGLView. (Deprecated: set setOpenGLView instead. Will be removed in v1.0)
-
– attachInView:withFrame:attach in UIView using the given frame. It will create a EAGLView and use it. (Deprecated: set setOpenGLView instead. Will be removed in v1.0)
-
– displaySizereturns the display size of the OpenGL view in pixels
-
– applyOrientation
KoboldExtensions Methods
-
screenCenterGives you the screen center position (in points), ie half of the screen size
property -
screenCenterInPixelsGives you the screen center position (in pixels), ie half of the screen size
property -
screenRectGives you the screen size as a CGRect (in points) spanning from 0, 0 to screenWidth, screenHeight
property -
screenRectInPixelsGives you the screen size as a CGRect (in pixels) spanning from 0, 0 to screenWidth, screenHeight
property -
screenSizeGives you the screen size as a CGSize struct (in points)
property -
screenSizeInPixelsGives you the screen size as a CGSize struct (in pixels)
property -
screenSizeAsPointGives you the screen size as a CGPoint struct (in points)
property -
screenSizeAsPointInPixelsGives you the screen size as a CGPoint struct (in pixels)
property -
isSceneStackEmptyChecks if the scene stack is still empty, which means runWithScene hasn’t been called yet.
property -
currentPlatformIsIOSTells you if the app is currently running on iOS.
property -
currentPlatformIsMacTells you if the app is currently running on Mac.
property -
currentDeviceIsSimulatorTells you if the app is currently running in the iPhone/iPad Simulator.
property -
currentDeviceIsIPadTells you if the app is currently running on the iPad rather than iPhone or iPod Touch.
property -
frameCountReturns the number of frames drawn since the start of the app. You can use this to check if certain events occured in the same frame, to ensure that something happens exactly n frames from now regardless of framerate, or to implement a custom framerate display. The frameCount variable is never reset at runtime, only when the app is restarted. An overflow occurs if the app remains running for over 828 days of continuous operation, assuming a steady 60 frames per second.
property -
– isRetinaDisplayEnabledTells you whether Retina Display is currently enabled. It does not tell you if the device you’re running has a Retina display. it could be a Retina device but Retina display may simply not be enabled.
-
– contentScaleFactorInverseGives you the inverse of the scale factor: 1.0f / contentScaleFactor
-
– contentScaleFactorHalvedGives you the scale factor halved: contentScaleFactor * 0.5f
iOSExtension Methods
-
touchDispatchersets the CCTouchDispatcher (iOS only)
property -
– setContentScaleFactor: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. In non High-res device the contentScale will be emulated.
-
– enableRetinaDisplay:Will enable Retina Display on devices that supports it. It will enable Retina Display on iPhone4 and iPod Touch 4. It will return YES, if it could enabled it, otherwise it will return NO.
-
– contentScaleFactorreturns the content scale factor
-
– convertTouchToGL:converts a UITouch to a GL point
Deprecated Methods
MacExtension Methods
-
eventDispatchersets the CCEventDispatcher (Mac only)
property -
– convertEventToGL:converts an NSEvent to GL coordinates (Mac only)
SwizzledMethods Methods
Properties
actionManager
CCActionManager associated with this director
@property (nonatomic, readwrite, retain) CCActionManager *actionManagerAvailability
Declared In
CCDirector.hanimationInterval
The FPS value
@property (nonatomic, readwrite, assign) NSTimeInterval animationIntervalDeclared In
CCDirector.hcontentScaleFactor
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. In non High-res device the contentScale will be emulated.
@property (nonatomic, readwrite) CGFloat contentScaleFactorAvailability
Discussion
Warning: Emulation of High-Res on iOS < 4 is an EXPERIMENTAL feature.
Declared In
CCDirector.hcurrentDeviceIsIPad
Tells you if the app is currently running on the iPad rather than iPhone or iPod Touch.
@property (nonatomic, readonly) BOOL currentDeviceIsIPadDeclared In
CCDirectorExtensions.hcurrentDeviceIsSimulator
Tells you if the app is currently running in the iPhone/iPad Simulator.
@property (nonatomic, readonly) BOOL currentDeviceIsSimulatorDeclared In
CCDirectorExtensions.hcurrentPlatformIsIOS
Tells you if the app is currently running on iOS.
@property (nonatomic, readonly) BOOL currentPlatformIsIOSDeclared In
CCDirectorExtensions.hcurrentPlatformIsMac
Tells you if the app is currently running on Mac.
@property (nonatomic, readonly) BOOL currentPlatformIsMacDeclared In
CCDirectorExtensions.hdelegate
CCDirector delegate. It shall implement the CCDirectorDelegate protocol
@property (nonatomic, readwrite, assign) id<CCDirectorDelegate> delegateAvailability
Declared In
CCDirector.hdeviceOrientation
The device orientattion
@property (nonatomic, readwrite) ccDeviceOrientation deviceOrientationDeclared In
CCDirector.hdisplayFPS
Whether or not to display the FPS on the bottom-left corner
@property (nonatomic, readwrite, assign) BOOL displayFPSDeclared In
CCDirector.hdisplayStats
Whether or not to display director statistics
@property (nonatomic, readwrite, assign) BOOL displayStatsDeclared In
CCDirector.heventDispatcher
sets the CCEventDispatcher (Mac only)
@property (nonatomic, readwrite, retain) CCEventDispatcher *eventDispatcherDeclared In
CCDirectorMac.hframeCount
Returns the number of frames drawn since the start of the app. You can use this to check if certain events occured in the same frame, to ensure that something happens exactly n frames from now regardless of framerate, or to implement a custom framerate display. The frameCount variable is never reset at runtime, only when the app is restarted. An overflow occurs if the app remains running for over 828 days of continuous operation, assuming a steady 60 frames per second.
@property (nonatomic, readonly) NSUInteger frameCountDeclared In
CCDirectorExtensions.hisAnimating
Whether or not the Director is active (animating)
@property (nonatomic, readonly) BOOL isAnimatingDeclared In
CCDirector.hisSceneStackEmpty
Checks if the scene stack is still empty, which means runWithScene hasn’t been called yet.
@property (nonatomic, readonly) BOOL isSceneStackEmptyDeclared In
CCDirectorExtensions.hnextDeltaTimeZero
whether or not the next delta time will be zero
@property (nonatomic, readwrite, assign) BOOL nextDeltaTimeZeroDeclared In
CCDirector.hnotificationNode
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)
@property (nonatomic, readwrite, retain) id notificationNodeAvailability
Declared In
CCDirector.hopenGLView
The EAGLView, where everything is rendered
@property (nonatomic, readwrite, retain) EAGLView *openGLViewDeclared In
CCDirector.hpaused
Whether or not the Director is paused
@property (nonatomic, readonly, getter=isPaused) BOOL pausedDeclared In
CCDirector.hpixelFormat
Pixel format used to create the context
@property (nonatomic, readonly) tPixelFormat pixelFormatDeclared In
CCDirector.hprojection
Sets an OpenGL projection
@property (nonatomic, readwrite) ccDirectorProjection projectionDeclared 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. On iOS usually it is the main thread.
@property (readonly, nonatomic) NSThread *runningThreadAvailability
Declared In
CCDirector.hscheduler
CCScheduler associated with this director
@property (nonatomic, readwrite, retain) CCScheduler *schedulerAvailability
Declared In
CCDirector.hscreenCenter
Gives you the screen center position (in points), ie half of the screen size
@property (nonatomic, readonly) CGPoint screenCenterDeclared In
CCDirectorExtensions.hscreenCenterInPixels
Gives you the screen center position (in pixels), ie half of the screen size
@property (nonatomic, readonly) CGPoint screenCenterInPixelsDeclared In
CCDirectorExtensions.hscreenRect
Gives you the screen size as a CGRect (in points) spanning from 0, 0 to screenWidth, screenHeight
@property (nonatomic, readonly) CGRect screenRectDeclared In
CCDirectorExtensions.hscreenRectInPixels
Gives you the screen size as a CGRect (in pixels) spanning from 0, 0 to screenWidth, screenHeight
@property (nonatomic, readonly) CGRect screenRectInPixelsDeclared In
CCDirectorExtensions.hscreenSize
Gives you the screen size as a CGSize struct (in points)
@property (nonatomic, readonly) CGSize screenSizeDeclared In
CCDirectorExtensions.hscreenSizeAsPoint
Gives you the screen size as a CGPoint struct (in points)
@property (nonatomic, readonly) CGPoint screenSizeAsPointDeclared In
CCDirectorExtensions.hscreenSizeAsPointInPixels
Gives you the screen size as a CGPoint struct (in pixels)
@property (nonatomic, readonly) CGPoint screenSizeAsPointInPixelsDeclared In
CCDirectorExtensions.hscreenSizeInPixels
Gives you the screen size as a CGSize struct (in pixels)
@property (nonatomic, readonly) CGSize screenSizeInPixelsDeclared In
CCDirectorExtensions.hsecondsPerFrame
seconds per frame
@property (nonatomic, readonly) ccTime secondsPerFrameDeclared In
CCDirector.hsendCleanupToScene
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.
@property (nonatomic, readonly) BOOL sendCleanupToSceneAvailability
Declared In
CCDirector.hClass Methods
setDirectorType:
There are 4 types of Director. – kCCDirectorTypeNSTimer (default) – kCCDirectorTypeMainLoop – kCCDirectorTypeThreadMainLoop – kCCDirectorTypeDisplayLink
+ (BOOL)setDirectorType:(ccDirectorType)directorTypeAvailability
Discussion
Each Director has it’s own benefits, limitations. If you are using SDK 3.1 or newer it is recommed to use the DisplayLink director
This method should be called before any other call to the director.
It will return NO if the director type is kCCDirectorTypeDisplayLink and the running SDK is < 3.1. Otherwise it will return YES.
Declared In
CCDirector.hInstance Methods
attachInView:
attach in UIView using the full frame. It will create a EAGLView. (Deprecated: set setOpenGLView instead. Will be removed in v1.0)
- (BOOL)attachInView:(UIView *)viewDeclared In
CCDirector.hattachInView:withFrame:
attach in UIView using the given frame. It will create a EAGLView and use it. (Deprecated: set setOpenGLView instead. Will be removed in v1.0)
- (BOOL)attachInView:(UIView *)view withFrame:(CGRect)frameDeclared In
CCDirector.hattachInWindow:
attach in UIWindow using the full frame. It will create a EAGLView. (Deprecated: set setOpenGLView instead. Will be removed in v1.0)
- (BOOL)attachInWindow:(UIWindow *)windowDeclared In
CCDirector.hcontentScaleFactor
returns the content scale factor
- (CGFloat)contentScaleFactorDeclared In
CCDirectorIOS.hcontentScaleFactorHalved
Gives you the scale factor halved: contentScaleFactor * 0.5f
- (float)contentScaleFactorHalvedDeclared In
CCDirectorExtensions.hcontentScaleFactorInverse
Gives you the inverse of the scale factor: 1.0f / contentScaleFactor
- (float)contentScaleFactorInverseDeclared In
CCDirectorExtensions.hconvertEventToGL:
converts an NSEvent to GL coordinates (Mac only)
- (CGPoint)convertEventToGL:(NSEvent *)eventDeclared In
CCDirectorMac.hconvertToGL:
converts a UIKit coordinate to an OpenGL coordinate Useful to convert (multi) touch coordinates to the current layout (portrait or landscape)
- (CGPoint)convertToGL:(CGPoint)pDeclared In
CCDirector.hconvertToUI:
converts an OpenGL coordinate to a UIKit coordinate Useful to convert node points to window points for calls such as glScissor
- (CGPoint)convertToUI:(CGPoint)pDeclared In
CCDirector.hconvertTouchToGL:
converts a UITouch to a GL point
- (CGPoint)convertTouchToGL:(UITouch *)touchDeclared In
CCDirectorIOS.hdisplaySize
returns the display size of the OpenGL view in pixels
- (CGSize)displaySizeDeclared In
CCDirector.hdrawScene
Draw the scene. This method is called every frame. Don’t call it manually.
- (void)drawSceneDeclared In
CCDirector.henableRetinaDisplay:
Will enable Retina Display on devices that supports it. It will enable Retina Display on iPhone4 and iPod Touch 4. It will return YES, if it could enabled it, otherwise it will return NO.
- (BOOL)enableRetinaDisplay:(BOOL)enableRetinaAvailability
Discussion
This is the recommended way to enable Retina Display.
Declared In
CCDirectorIOS.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.hisRetinaDisplayEnabled
Tells you whether Retina Display is currently enabled. It does not tell you if the device you’re running has a Retina display. it could be a Retina device but Retina display may simply not be enabled.
- (BOOL)isRetinaDisplayEnabledDeclared In
CCDirectorExtensions.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.hpopToRootScene
Pops out all scenes from the queue until the root scene in 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)popToRootSceneDeclared 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)purgeCachedDataAvailability
Declared In
CCDirector.hpushScene:
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)pushScene:(CCScene *)sceneDeclared In
CCDirector.hreplaceScene:
Replaces the running scene with a new one. The running scene is terminated. ONLY call it if there is a running scene.
- (void)replaceScene:(CCScene *)sceneDeclared In
CCDirector.hreshapeProjection:
changes the projection size
- (void)reshapeProjection:(CGSize)newWindowSizeDeclared 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. Call it to run only your FIRST scene. Don’t call it if there is already a running scene.
- (void)runWithScene:(CCScene *)sceneDiscussion
It will call pushScene: and then it will call startAnimation
Declared In
CCDirector.hsetAlphaBlending:
enables/disables OpenGL alpha blending
- (void)setAlphaBlending:(BOOL)onDeclared In
CCDirector.hsetContentScaleFactor:
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. In non High-res device the contentScale will be emulated.
- (void)setContentScaleFactor:(CGFloat)scaleFactorAvailability
Discussion
The recommend way to enable Retina Display is by using the “enableRetinaDisplay:(BOOL)enabled” method.
Declared In
CCDirectorIOS.hsetDepthBufferFormat:
Change depth buffer format of the render buffer. Call this class method before attaching it to a UIWindow/UIView Default depth buffer: 0 (none). Supported: kCCDepthBufferNone, kCCDepthBuffer16, and kCCDepthBuffer24 (Deprecated: Set the depth buffer format when creating the EAGLView. This method will be removed in v1.0)
- (void)setDepthBufferFormat:(tDepthBufferFormat)dbDeclared In
CCDirector.hsetDepthTest:
enables/disables OpenGL depth test
- (void)setDepthTest:(BOOL)onDeclared In
CCDirector.hsetGLDefaultValues
sets the OpenGL default values
- (void)setGLDefaultValuesDeclared In
CCDirector.hsetPixelFormat:
Uses a new pixel format for the EAGLView. Call this class method before attaching it to a UIView Default pixel format: kRGB565. Supported pixel formats: kRGBA8 and kRGB565 (Deprecated: Set the pixel format when creating the EAGLView. This method will be removed in v1.0)
- (void)setPixelFormat:(tPixelFormat)pDeclared 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.h