cocos2d for iPhone  2.1.0
2D game engine for iOS and OS X
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
Instance Methods | Class Methods | Properties | List of all members
CCDirector Class Reference

#import <CCDirector.h>

Inheritance diagram for CCDirector:
Inheritance graph
[legend]
Collaboration diagram for CCDirector:
Collaboration graph
[legend]

Instance Methods

(CGSize) - winSize
 
(CGSize) - winSizeInPixels
 
(void) - reshapeProjection:
 
(void) - setViewport
 
(CGPoint) - convertToGL:
 
(CGPoint) - convertToUI:
 
(float) - getZEye
 XXX: missing description.
 
(void) - runWithScene:
 
(void) - pushScene:
 
(void) - popScene
 
(void) - popToRootScene
 
(void) - popToSceneStackLevel:
 
(void) - replaceScene:
 
(void) - end
 
(void) - pause
 
(void) - resume
 
(void) - stopAnimation
 
(void) - startAnimation
 
(void) - drawScene
 
(void) - setView:
 
(CCGLView *) - view
 
(void) - purgeCachedData
 
(void) - setGLDefaultValues
 
(void) - setAlphaBlending:
 
(void) - setDepthTest:
 
(void) - createStatsLabel
 
(void) - setContentScaleFactor:
 
(BOOL) - enableRetinaDisplay:
 
(CGFloat) - contentScaleFactor
 
(CGPoint) - convertTouchToGL:
 
(CGPoint) - convertEventToGL:
 

Class Methods

(CCDirector *) + sharedDirector
 

Properties

NSThread * runningThread
 
CCScenerunningScene
 
NSTimeInterval animationInterval
 
BOOL displayStats
 
BOOL nextDeltaTimeZero
 
BOOL paused
 
BOOL isAnimating
 
ccDirectorProjection projection
 
NSUInteger totalFrames
 
ccTime secondsPerFrame
 
BOOL sendCleanupToScene
 
id notificationNode
 
id< CCDirectorDelegatedelegate
 
CCScheduler * scheduler
 
CCActionManageractionManager
 
CCTouchDispatchertouchDispatcher
 
CCEventDispatchereventDispatcher
 

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:

Since the CCDirector is a singleton, the standard way to use it is by calling:

The CCDirector also sets the default OpenGL context:

Definition at line 84 of file CCDirector.h.

Method Documentation

- (CGFloat) contentScaleFactor

returns the content scale factor

Provided by category CCDirector(iOSExtension).

- (CGPoint) convertEventToGL: (NSEvent *)  event

converts an NSEvent to GL coordinates (Mac only)

- (CGPoint) convertToGL: (CGPoint)  p

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

- (CGPoint) convertTouchToGL: (UITouch *)  touch

converts a UITouch to a GL point

Provided by category CCDirector(iOSExtension).

- (CGPoint) convertToUI: (CGPoint)  p

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

- (void) createStatsLabel

creates the Stats labels

- (void) drawScene

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

Implemented in CCDirectorIOS.

- (BOOL) enableRetinaDisplay: (BOOL)  enableRetina

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.

This is the recommended way to enable Retina Display.

Since
v0.99.5

Provided by category CCDirector(iOSExtension).

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

- (float) getZEye

XXX: missing description.

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

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

- (void) popToSceneStackLevel: (NSUInteger)  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

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.

Since
v0.99.3
- (void) pushScene: (CCScene *)  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: (CCScene *)  scene

Replaces the running scene with a new one. The running scene is terminated. ONLY call it if there is a running scene.

- (void) reshapeProjection: (CGSize)  newWindowSize

changes the projection size

- (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: (CCScene *)  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) setAlphaBlending: (BOOL)  on

enables/disables OpenGL alpha blending

- (void) setContentScaleFactor: (CGFloat)  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. In non High-res device the contentScale will be emulated.

The recommend way to enable Retina Display is by using the "enableRetinaDisplay:(BOOL)enabled" method.

Since
v0.99.4

Provided by category CCDirector(iOSExtension).

- (void) setDepthTest: (BOOL)  on

enables/disables OpenGL depth test

- (void) setGLDefaultValues

sets the OpenGL default values

- (void) setView: (CCGLView *)  view

sets the openGL view

- (void) setViewport

Sets the glViewport

+ (CCDirector*) sharedDirector

returns a shared instance of the director

- (void) startAnimation

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

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.

- (CCGLView*) view

returns the OpenGL view

- (CGSize) winSize

returns the size of the OpenGL view in points

- (CGSize) winSizeInPixels

returns the size of the OpenGL view in pixels. On Mac winSize and winSizeInPixels return the same value.

Property Documentation

- (CCActionManager*) actionManager
readwritenonatomicretain

CCActionManager associated with this director

Since
v2.0

Definition at line 209 of file CCDirector.h.

- (NSTimeInterval) animationInterval
readwritenonatomicassign

The FPS value

Definition at line 166 of file CCDirector.h.

- (id<CCDirectorDelegate>) delegate
readwritenonatomicassign

CCDirector delegate. It shall implement the CCDirectorDelegate protocol

Since
v0.99.5

Definition at line 199 of file CCDirector.h.

- (BOOL) displayStats
readwritenonatomicassign

Whether or not to display director statistics

Definition at line 168 of file CCDirector.h.

- (CCEventDispatcher*) eventDispatcher
readwritenonatomicretain

sets the CCEventDispatcher (Mac only)

Definition at line 46 of file CCDirectorMac.h.

- (BOOL) isAnimating
readnonatomicassign

Whether or not the Director is active (animating)

Definition at line 174 of file CCDirector.h.

- (BOOL) nextDeltaTimeZero
readwritenonatomicassign

whether or not the next delta time will be zero

Definition at line 170 of file CCDirector.h.

- (id) notificationNode
readwritenonatomicretain

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

Definition at line 194 of file CCDirector.h.

- (BOOL) paused
readnonatomicassign

Whether or not the Director is paused

Definition at line 172 of file CCDirector.h.

- (ccDirectorProjection) projection
readwritenonatomicassign

Sets an OpenGL projection

Definition at line 176 of file CCDirector.h.

- (CCScene*) runningScene
readnonatomicassign

The current running Scene. Director can only run one Scene at the time

Definition at line 164 of file CCDirector.h.

- (NSThread*) runningThread
readnonatomicassign

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.

Since
v0.99.5

Definition at line 162 of file CCDirector.h.

- (CCScheduler*) scheduler
readwritenonatomicretain

CCScheduler associated with this director

Since
v2.0

Definition at line 204 of file CCDirector.h.

- (ccTime) secondsPerFrame
readnonatomicassign

seconds per frame

Definition at line 180 of file CCDirector.h.

- (BOOL) sendCleanupToScene
readnonatomicassign

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

Definition at line 187 of file CCDirector.h.

- (NSUInteger) totalFrames
readnonatomicassign

How many frames were called since the director started

Definition at line 178 of file CCDirector.h.

- (CCTouchDispatcher*) touchDispatcher
readwritenonatomicretain

sets the CCTouchDispatcher (iOS only)

Provided by category CCDirector(iOSExtension).

Definition at line 42 of file CCDirectorIOS.h.


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