Inherits from | CC_VIEWCONTROLLER |
Declared in | CCDirector.h |
The director creates and handles the main Window and the Cocos2D view. It also presents Scenes and initiates scene updates and drawing.
director创建和处理主窗口和Cocos2D的view,同时显示Scenes和初始化scene的更新和绘制。
CCDirector inherits from CC_VIEWCONTROLLER which is equivalent to UIViewController on iOS, and NSObject on OS X and Android.
CCDiretor继承自CC_VIEWCONTROLLER,相当于iOs的UIViewController
Since the CCDirector is a singleton, the standard way to use its methods and properties is:
[[CCDirector sharedDirector] methodName];
[CCDirector sharedDirector].aProperty;
因为CCDirector是单例模式,所以表示的使用方法和属性为:
[[CCDirector sharedDirector] methodName];
[[CCDirector sharedDirector].aProperty;
The CCDirector is responsible for:
CCDirector负责:
初始化OPENGL ES/Metal内容
设置像素格式(默认为RGB565)
设置缓存深度(默认为0bit)
设置投影(在3D中默认是1)
The CCDirector also sets the default OpenGL context:
GL_TEXTURE_2D
is enabledGL_VERTEX_ARRAY
is enabledGL_COLOR_ARRAY
is enabledGL_TEXTURE_COORD_ARRAY
is enabled runningThread
property contentScaleFactor
property UIScaleFactor
property designSize
property view
property projection
property projectionMatrix
property globalShaderUniforms
property displayStats
property– viewSize
– viewSizeInPixels
– reshapeProjection:
– convertToGL:
– convertToUI:
runningScene
property– presentScene:
– presentScene:withTransition:
– pushScene:
– popScene
– popToRootScene
– popToRootSceneWithTransition:
– pushScene:withTransition:
– popSceneWithTransition:
animationInterval
property fixedUpdateInterval
property nextDeltaTimeZero
property paused
property animating
property totalFrames
property secondsPerFrame
property– end
– pause
– resume
– stopAnimation
– startAnimation
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
CCDirector.h
Whether or not the Director is active (animating).
@property (nonatomic, readonly, getter=isAnimating) BOOL animating
CCDirector.h
The animation interval is the time per frame. Typically specified as 1.0 / 60.0
where the latter number defines the framerate. The lowest value is 0.0166 (1/60).
@property (nonatomic, readwrite, assign) CCTime animationInterval
CCDirector.h
Content scaling factor. Sets the ratio of points to pixels. Default value is initalized from the content scale of the GL view used by the director.
@property (nonatomic, assign) CGFloat contentScaleFactor
CCDirector.h
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
CCDirector.h
Whether or not to display statistics in the view’s lower left corner. From top to bottom the numbers are: number of draw calls, time per frame (in seconds), framerate (average over most recent frames).
@property (nonatomic, readwrite, assign) BOOL displayStats
CCDirector.h
The fixed animation interval is used to run “fixed updates” at a fixed rate, independently of the framerate. Used primarly by the physics engine.
@property (nonatomic, readwrite, assign) CCTime fixedUpdateInterval
CCDirector.h
The current global shader values values.
@property (nonatomic, readonly) NSMutableDictionary *globalShaderUniforms
CCDirector.h
whether or not the next delta time will be zero
@property (nonatomic, readwrite, assign, getter=isNextDeltaTimeZero) BOOL nextDeltaTimeZero
CCDirector.h
Whether or not the Director is paused.
@property (nonatomic, readonly, getter=isPaused) BOOL paused
CCDirector.h
Sets an OpenGL projection
@property (nonatomic, readwrite) CCDirectorProjection projection
CCDirector.h
Projection matrix used for rendering.
@property (nonatomic, readonly) GLKMatrix4 projectionMatrix
CCDirector.h
The current running Scene. Director can only run one Scene at a time.
@property (nonatomic, readonly) CCScene *runningScene
CCDirector.h
If you want to run any Cocos2D task, run it in this thread. Any task that modifies Cocos2D’s OpenGL state must be executed on this thread due to OpenGL state changes only being allowed on the OpenGL thread.
@property (weak, readonly, nonatomic) NSThread *runningThread
The Cocos2D thread, typically this will be the main thread.
CCDirector.h
Time it took to render the most recent frames, in seconds per frame.
@property (nonatomic, readonly) CCTime secondsPerFrame
CCDirector.h
How many frames were called since the director started
@property (nonatomic, readonly) NSUInteger totalFrames
CCDirector.h
Converts a UIKit coordinate to an OpenGL coordinate.
- (CGPoint)convertToGL:(CGPoint)p
Point to convert.
Converted point.
Useful to convert (multi) touch coordinates to the current layout (portrait or landscape).
CCDirector.h
Converts an OpenGL coordinate to a UIKit coordinate.
- (CGPoint)convertToUI:(CGPoint)p
Point to convert.
Converted point.
Useful to convert node points to window points for calls such as glScissor.
CCDirector.h
Ends the execution, releases the running scene. It doesn’t remove the view from the view hierarchy. You have to do it manually.
- (void)end
CCDirector.h
Pauses the running scene. All scheduled timers and actions will be paused. When paused, the director refreshes the screen at a very low framerate (4 fps) to conserve battery power.
- (void)pause
CCDirector.h
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.
- (void)popScene
Warning: ONLY call it if there is a running scene.
CCDirector.h
Replaces the running scene, with the last scene pushed to the stack, using a transition
- (void)popSceneWithTransition:(CCTransition *)transition
The transition to use
CCDirector.h
Pops out all scenes from the queue until the root scene in the queue.
- (void)popToRootScene
This scene will replace the running one. Internally it will call popToSceneStackLevel:1
CCDirector.h
Pops out all scenes from the queue until the root scene in the queue, using a transition
- (void)popToRootSceneWithTransition:(CCTransition *)transition
The transition to play.
This scene will replace the running one. Internally it will call popToRootScene
CCDirector.h
Presents a new scene.
- (void)presentScene:(CCScene *)scene
Scene to start.
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.
CCDirector.h
Presents a new scene, with a transition.
呈现一个新的scene,加入变化过程。
- (void)presentScene:(CCScene *)scene withTransition:(CCTransition *)transition
Scene to start.
Transition to use. Can be nil.
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.
CCDirector.h
Removes all the cocos2d resources that have been previously loaded and automatically cached, textures for instance.
- (void)purgeCachedData
CCDirector.h
Suspends the execution of the running scene, pushing it on the stack of suspended scenes.
- (void)pushScene:(CCScene *)scene
New scene to start.
The new scene will be executed, the previous scene remains in memory. Try to avoid big stacks of pushed scenes to reduce memory allocation.
Warning: ONLY call it if there is already a running scene.
CCDirector.h
Pushes the running scene onto the scene stack, and presents the incoming scene, using a transition
- (void)pushScene:(CCScene *)scene withTransition:(CCTransition *)transition
The scene to present
The transition to use
CCDirector.h
Changes the projection size.
- (void)reshapeProjection:(CGSize)newViewSize
New projection size.
CCDirector.h
Resumes the paused scene and its scheduled timers and actions. The “delta time” will be set to 0 as if the game wasn’t paused.
- (void)resume
CCDirector.h
Begins drawing the screen. Scheduled timers and actions will run.
- (void)startAnimation
Warning: Don’t call this function to start the main loop. To run the main loop call presentScene:
CCDirector.h
Stops the animation. All scheduled updates and actions are effectively paused.
- (void)stopAnimation
When not animating, the director doesn’t redraw the view at all. It is best to hide the view when not animating the director. If you need to keep showing the director’s view use pause instead.
CCDirector.h
The size of the view in points.
- (CGSize)viewSize
The size of the view in points.
CCDirector.h