CCDirector--Cocos2D-Swift v3.3

CCDirector Class Reference

Inherits from CC_VIEWCONTROLLER
Declared in CCDirector.h

Overview

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:

  • initializing the OpenGL ES / Metal context
  • setting the pixel format (default on is RGB565)
  • setting the buffer depth (default one is 0-bit)
  • setting the projection (default one is 3D)

CCDirector负责:

初始化OPENGL ES/Metal内容

设置像素格式(默认为RGB565)

设置缓存深度(默认为0bit)

设置投影(在3D中默认是1)

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

Singleton Accessor

Accessing OpenGL Thread

View Scale

Working with View and Projection

Presenting Scenes

Animating the Active Scene

Purging Caches

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

See Also

Declared In

CCDirector.h

animating

Whether or not the Director is active (animating).

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

See Also

Declared In

CCDirector.h

animationInterval

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

See Also

Declared In

CCDirector.h

contentScaleFactor

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

See Also

Declared In

CCDirector.h

designSize

User definable value that is used for default contentSizes of many node types (CCSceneCCNodeColor, etc). Defaults to the view size.

@property (nonatomic, assign) CGSize designSize

Declared In

CCDirector.h

displayStats

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

See Also

Declared In

CCDirector.h

fixedUpdateInterval

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

See Also

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

See Also

Declared In

CCDirector.h

projection

Sets an OpenGL projection

@property (nonatomic, readwrite) CCDirectorProjection projection

See Also

Declared In

CCDirector.h

projectionMatrix

Projection matrix used for rendering.

@property (nonatomic, readonly) GLKMatrix4 projectionMatrix

See Also

Declared In

CCDirector.h

runningScene

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

@property (nonatomic, readonly) CCScene *runningScene

See Also

Declared In

CCDirector.h

runningThread

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

Return Value

The Cocos2D thread, typically this will be the main thread.

Declared In

CCDirector.h

secondsPerFrame

Time it took to render the most recent frames, in seconds per frame.

@property (nonatomic, readonly) CCTime secondsPerFrame

See Also

Declared In

CCDirector.h

totalFrames

How many frames were called since the director started

@property (nonatomic, readonly) NSUInteger totalFrames

See Also

Declared In

CCDirector.h

view

View used by the director for rendering. The CC_VIEW macro equals UIView on iOS, NSOpenGLView on OS X and CCGLView on Android.

@property (nonatomic, strong) CC_VIEW<CCDirectorView> *view

See Also

Declared In

CCDirector.h

Class Methods

sharedDirector

The shared director instance.

返回一个shared director实例

+ (CCDirector *)sharedDirector

Return Value

The shared director instance.

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 view from the view hierarchy. You have to do it manually.

- (void)end

Declared In

CCDirector.h

pause

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

See Also

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.

- (void)popScene

Discussion

Warning: ONLY call it if there is a running scene.

See Also

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

See Also

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

See Also

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

Parameters

transition

The transition to play.

Discussion

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

See Also

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.

See Also

Declared In

CCDirector.h

presentScene:withTransition:

Presents a new scene, with a transition.

呈现一个新的scene,加入变化过程。

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

Parameters

scene

Scene to start.

transition

Transition to use. Can be nil.

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.

See Also

Declared In

CCDirector.h

purgeCachedData

Removes all the cocos2d resources that have been previously loaded and automatically cached, textures for instance.

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

See Also

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

See Also

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 and its scheduled timers and actions. The “delta time” will be set to 0 as if the game wasn’t paused.

- (void)resume

See Also

Declared In

CCDirector.h

startAnimation

Begins drawing the screen. Scheduled timers and actions will run.

- (void)startAnimation

Discussion

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

See Also

Declared In

CCDirector.h

stopAnimation

Stops the animation. All scheduled updates and actions are effectively paused.

- (void)stopAnimation

Discussion

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.

See Also

Declared In

CCDirector.h

viewSize

The size of the view in points.

- (CGSize)viewSize

Return Value

The size of the view in points.

See Also

Declared In

CCDirector.h

viewSizeInPixels

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

- (CGSize)viewSizeInPixels

Return Value

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

See Also

Declared In

CCDirector.h

时间: 2024-10-26 14:28:52

CCDirector--Cocos2D-Swift v3.3的相关文章

cocos2D(三)---- 第一cocos2d的程序代码分析

在第一讲中已经新建了第一个cocos2d程序,执行效果例如以下: 在这讲中我们来分析下里面的代码,了解cocos2d的工作原理,看看屏幕上的这个"Hello World"是怎样显示出来的. 这是HelloWorld项目的代码结构: 以下,我们開始分析项目中的这些源文件: 从程序的入口点開始 这么多源文件在这里,到底先看哪个呢?有些人可能会先挑内容少的来看,认为这样就能够轻松解决掉一个源文件了.事实上这是不正确的,这样看起来更加是一头雾水,根本搞不清楚每一个源文件之间的联系.正确的做法应

@最新CAX/EDA/CFD/GIS/光学/化工/液压软件资源网

最新CAX/EDA/CFD/GIS/光学/化工/液压软件资源网 阳光软件园 所有软件资料都随时更新,急需软件可以去看看,基本上能找到你想要的! http://zhangqg.51.net http://cax2one.f3322.net e-mail: [email protected];[email protected];[email protected] 将以上任意链接连接起来输入IE 窗口即可进入网站 下面是一部分软件,更多软件在我们的软件列表,如需要请到列表中去找! ACTRAN v14

好几年才收集到的软件,分享给大家。。。

QQ:365543212Email:[email protected]请按Clrt+F查找,输入软件关键字查询(不要输入版本号),如果找不到,您可以咨询客服.................FD......................12D MODEL 7.0 规划设计232Analyzer v4.1 高级串口分析监测3D Home Architect Design Suite Deluxe 8.0 室内装潢3D Profiler Tools 11.2 For Archicad 113D R

iOS 学习资料

(适合初学者) 本文资料来源于GitHub 一.视频教程(英文) Developing iOS 7 Apps for iPhone and iPad斯坦福开放教程之一, 课程主要讲解了一些 iOS 开发工具和 API 以及 iOS SDK 的使用, 属于 iOS 基础视频 iPad and iPhone Application Development该课程的讲师 Paul Hegarty 是斯坦福大学软件工程学教授, 视频内容讲解得深入, 权威, 深受好评 Advanced iPhone Dev

Cocos2d-x 物理引擎及碰撞

基础知识: 1 #ifndef __HELLOWORLD_SCENE_H__ 2 #define __HELLOWORLD_SCENE_H__ 3 4 #include "cocos2d.h" 5 6 class HelloWorld : public cocos2d::Layer 7 { 8 private: 9 Size visibleSize; 10 public: 11 // there's no 'id' in cpp, so we recommend returning t

(18)数据结构

cocos2d::Vector v3.0 beta加入 定义在"COCOS2DX_ROOT/cocos/base"的"CCVector.h"头文件中. template<class T>class CC_DLL Vector; cocos2d::Vector<T>是一个封装好的能动态增长顺序访问的容器. cocos2d::Vector<T>中的元素是按序存取的,它的低层实现数据结构是标准模版库中的标准顺序容器std::vector

精品软件3

QQ:365543212 ..................................... MAGMASOFT产品: MAGMASOFT v4.4 Windows & Linux & HPux & Solaris-ISO 1DVD(完全解密版本,无网格数量限制,可以计算的铸造仿真软件) MagmaSoft.v4.4.SP3.4-ISO 1DVD MAGMASOFT v4.4 P28-ISO 1CD Magmasoft 中文教程 MAGNA POWERTRAIN产品: AE

iOS-- (转)学习资料整理 推荐必读!!!

iOS 学习资料整理 2015-01-12 11:31 420人阅读 评论(0) 收藏 举报  分类: 其它(50)  目录(?)[+] 这份学习资料是为 iOS 初学者所准备的, 旨在帮助 iOS 初学者们快速找到适合自己的学习资料, 节省他们搜索资料的时间, 使他们更好的规划好自己的 iOS 学习路线, 更快的入门, 更准确的定位的目前所处的位置. 该文档会持续更新, 同时也欢迎更多具有丰富经验的 iOS 开发者将自己的常用的一些工具, 学习资料, 学习心得等分享上来, 我将定期筛选合并,

iOS 学习资料整理集合

视频教程(英文) Developing iOS 7 Apps for iPhone and iPad 斯坦福开放教程之一, 课程主要讲解了一些 iOS 开发工具和 API 以及 iOS SDK 的使用, 属于 iOS 基础视频 iPad and iPhone Application Development 该课程的讲师 Paul Hegarty 是斯坦福大学软件工程学教授, 视频内容讲解得深入, 权威, 深受好评 Advanced iPhone Development - Fall 2010 i

iOS 学习资料整理(转)

视频教程(英文) 视频教程(中文) 书籍 博客 文章 相关网站 社区 工具/插件 GitHub Top 50 简介 邮件订阅 文档 指南 Awesome 系列 知乎上的讨论 Quora 上的讨论 贡献者 License 这份学习资料是为 iOS 初学者所准备的, 旨在帮助 iOS 初学者们快速找到适合自己的学习资料, 节省他们搜索资料的时间, 使他们更好的规划好自己的 iOS 学习路线, 更快的入门, 更准确的定位的目前所处的位置. 该文档会持续更新, 同时也欢迎更多具有丰富经验的 iOS 开发