Cocos2d-API风格说明
2016-10-18 17:47
253 查看
两阶段构造器及静态create()函数
第一阶段:运行C++类构造器
在C++类默认构造器中,成员变量必须设定为默认值,但不应该在它里面编写任何逻辑,因为不会返回值。Myclass::MyClass(): _data(NULL), _flag(false), _count(0) { memset(_array, 0, sizeof(_array)); }
第二阶段:调用MyClass:init()函数
bool MyClass::initWithFilename(const std::string& filename) { // just take loading texture as a sample, this behaviour can fail if the image file doesn't exist. bool bReturnValue = loadTextureIntoMemory(filename); return bReturnValue; }
所以,可以构建这样一段代码:
MyClass* obj = new MyClass; if (true == obj->initWithFilename("texture.png")) { // congratulations, go ahead! } else { // error process }
在Cocos2d-x中,已经包装好这两阶段的构造器,并且在create()中会自动释放引用计数,每一个cocos2d类都有自己的静态create方法。
doSomething()
doWithResource()
onEvenCallback()
onAction表明这是一种回调函数,当引发一定条件时,其它类可以调用这种方法。getInstance
单例模式类,没有create方法,但是有getInstance方法,对应的析构方法为destroyInstance()。属性:getter和setter
setProperty()
改变属性的值getProperty()
因为不能修改属性,所以使用const,例如const CCSize& getSize() const;isProperty()
类似getProperty,返回类型为bool。总结
如果属性为“只读”,将不会有 setProperty(type) 方法;如果属性为一个bool值,将会有 setProperty(bool) 及 isProperty() 方法。 比如: Sprite::isDirty() 和 Sprite::setDirty(bool bDirty) 。
如果属性不是一个bool值,将会有 setProperty(type) 和 getProperty() 方法。比如: void Sprite::setTexture(Texture2D*) 和 Texture2D* CCSprite::getTexture() 。
相关文章推荐
- 【cocos2d-js官方文档】十八、Cocos2d-JS v3.0中的属性风格API
- 【官方文档】#Cocos2d-JS v3.0中的属性风格API
- Cocos2d-x 综述——API 风格
- Cocos2d-x之绘图API说明
- Cocos2d-x CocosWidget项目配置与API说明
- Cocos2d-x CocosWidget 项目配置及API说明
- cocos2d-x v3.0发布说明和API修改
- Cocos API风格说明(Cocos2d-xV3.0以上版本)
- Cocos2d-x API风格说明
- Cocos2d-x CocosWidget 项目配置及API说明
- 【cocos2d-js公文】十八、Cocos2d-JS v3.0物业风格API
- 基站使用api说明
- 关于php能动态输出哪些内容以及四种风格标签说明
- 【官方文档】《暗黑世界V1.4》API说明!
- HighCharts 详细使用及API文档说明
- JFreeChart使用说明一--api介绍
- Spring整合Hibernate,不用HibernateDaoSupport与HibernateTemplate而用Hibernate自己的api分析说明
- jQuery验证控件jquery.validate.js使用说明+中文API
- SOCKET相关API说明
- 【cocos2d-js官方文档】三、Bake功能使用说明