# 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

- `runningThread` property
- `runningScene` property
- `animationInterval` property
- `displayStats` property
- `nextDeltaTimeZero` property
- `paused` property
- `animating` property
- `projection` property
- `totalFrames` property
- `secondsPerFrame` property
- `responderManager` property
- `delegate` property
- `contentScaleFactor` property
- `UIScaleFactor` property
- `designSize` property
- `projectionMatrix` property
- `globalShaderUniforms` property
- `+ 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 UIScaleFactor`

#### Declared In

`CCDirector.h`

### animating

Whether or not the Director is active (animating)

`@property (nonatomic, readonly, getter=isAnimating) BOOL animating`

#### Declared In

`CCDirector.h`

### animationInterval

The FPS value

`@property (nonatomic, readwrite, assign) CCTime animationInterval`

#### Declared In

`CCDirector.h`

### contentScaleFactor

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 contentScaleFactor`

#### Declared In

`CCDirector.h`

### delegate

CCDirector delegate. It shall implement the CCDirectorDelegate protocol

`@property (nonatomic, readwrite, weak) id<CCDirectorDelegate> delegate`

#### Declared In

`CCDirector.h`

### designSize

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 designSize`

#### Declared In

`CCDirector.h`

### displayStats

Whether or not to display director statistics

`@property (nonatomic, readwrite, assign) BOOL displayStats`

#### Declared In

`CCDirector.h`

### globalShaderUniforms

The current global shader values values.

`@property (nonatomic, readonly) NSMutableDictionary *globalShaderUniforms`

#### Declared In

`CCDirector.h`

### nextDeltaTimeZero

whether or not the next delta time will be zero

`@property (nonatomic, readwrite, assign, getter=isNextDeltaTimeZero) BOOL nextDeltaTimeZero`

#### Declared In

`CCDirector.h`

### paused

Whether or not the Director is paused

`@property (nonatomic, readonly, getter=isPaused) BOOL paused`

#### Declared In

`CCDirector.h`

### projection

Sets an OpenGL projection

`@property (nonatomic, readwrite) CCDirectorProjection projection`

#### Declared In

`CCDirector.h`

### projectionMatrix

Projection matrix used for rendering.

`@property (nonatomic, readonly) GLKMatrix4 projectionMatrix`

#### Declared In

`CCDirector.h`

### responderManager

Sets the touch manager

`@property (nonatomic, strong) CCResponderManager *responderManager`

#### Declared In

`CCDirector.h`

### runningScene

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

`@property (nonatomic, readonly) CCScene *runningScene`

#### Declared In

`CCDirector.h`

### runningThread

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 *runningThread`

#### Declared In

`CCDirector.h`

### secondsPerFrame

seconds per frame

`@property (nonatomic, readonly) CCTime secondsPerFrame`

#### Declared In

`CCDirector.h`

### totalFrames

How many frames were called since the director started

`@property (nonatomic, readonly) NSUInteger totalFrames`

#### Declared In

`CCDirector.h`

## Class Methods

### sharedDirector

returns a shared instance of the director

`+ (CCDirector *)sharedDirector`

#### Declared In

`CCDirector.h`

## Instance Methods

### convertToGL:

Converts a UIKit coordinate to an OpenGL coordinate.

`- (CGPoint)convertToGL:(CGPoint)p`

#### Parameters

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.h`

### convertToUI:

Converts an OpenGL coordinate to a UIKit coordinate.

`- (CGPoint)convertToUI:(CGPoint)p`

#### Parameters

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.h`

### end

Ends the execution, releases the running scene. It doesn’t remove the OpenGL view from its parent. You have to do it manually.

`- (void)end`

#### Declared In

`CCDirector.h`

### 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)pause`

#### Declared In

`CCDirector.h`

### 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)popScene`

#### Declared In

`CCDirector.h`

### popSceneWithTransition:

Replaces the running scene, with the last scene pushed to the stack, using a transition

`- (void)popSceneWithTransition:(CCTransition *)transition`

#### Parameters

transition

  The transition to use

#### Declared In

`CCDirector.h`

### popToRootScene

Pops out all scenes from the queue until the root scene in the queue.

`- (void)popToRootScene`

#### Discussion

This scene will replace the running one. Internally it will call `popToSceneStackLevel:1`

#### Declared In

`CCDirector.h`

### popToRootSceneWithTransition:

Pops out all scenes from the queue until the root scene in the queue, using a transition

`- (void)popToRootSceneWithTransition:(CCTransition *)transition`

#### Discussion

This scene will replace the running one. Internally it will call `popToRootScene`

#### Declared In

`CCDirector.h`

### presentScene:

Presents a new scene.

`- (void)presentScene:(CCScene *)scene`

#### Parameters

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.h`

### presentScene:withTransition:

Presents a new scene, with a transition.

`- (void)presentScene:(CCScene *)scene withTransition:(CCTransition *)transition`

#### Parameters

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.h`

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

`- (void)purgeCachedData`

#### Declared In

`CCDirector.h`

### pushScene:

Suspends the execution of the running scene, pushing it on the stack of suspended scenes.

`- (void)pushScene:(CCScene *)scene`

#### Parameters

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.h`

### pushScene:withTransition:

Pushes the running scene onto the scene stack, and presents the incoming scene, using a transition

`- (void)pushScene:(CCScene *)scene withTransition:(CCTransition *)transition`

#### Parameters

scene

  The scene to present

transition

  The transition to use

#### Declared In

`CCDirector.h`

### replaceScene:

Replaces the running scene with a new one. The running scene is terminated.

`- (void)replaceScene:(CCScene *)scene`

#### Parameters

scene

  New scene to start.

#### Discussion

ONLY call it if there is a running scene.

#### Declared In

`CCDirector.h`

### replaceScene: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 *)transition`

#### Parameters

scene

  The incoming scene

transition

  The transition to perform

#### Declared In

`CCDirector.h`

### reshapeProjection:

Changes the projection size.

`- (void)reshapeProjection:(CGSize)newViewSize`

#### Parameters

newViewSize

  New projection size.

#### Declared In

`CCDirector.h`

### 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)resume`

#### Declared In

`CCDirector.h`

### runWithScene:

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

`- (void)runWithScene:(CCScene *)scene`

#### Parameters

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.h`

### startAnimation

The main loop is triggered again. Call this function only if [stopAnimation] was called earlier

`- (void)startAnimation`

#### Discussion

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

#### Declared In

`CCDirector.h`

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

`- (void)stopAnimation`

#### Declared In

`CCDirector.h`

### view

returns the OpenGL view

`- (CCGLView *)view`

#### Declared In

`CCDirector.h`

### viewSize

returns the size of the OpenGL view in points

`- (CGSize)viewSize`

#### Declared In

`CCDirector.h`

### viewSizeInPixels

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

`- (CGSize)viewSizeInPixels`

#### Declared In

`CCDirector.h`