cocos2dx 宏:CC_PROPERTY
来源:互联网 发布:环境监测总站数据 编辑:程序博客网 时间:2024/05/02 04:42
勤奋努力,持之以恒!
cocos2d-x定义了很多宏定义,有助于我们提高开发效率
而CC_PROPERTY 用来声明一个protected变量。
使用CC_PROPERTY声明的变量可以使用getter获取变量的值,使用setter设置变量的值。
CC_PROPERTY的声明在CCPlatformMacros.h中,结构如下
/** CC_PROPERTY is used to declare a protected variable. We can use getter to read the variable, and use the setter to change the variable. @param varType : the type of variable. 变量类型 @param varName : variable name. 变量名称 @param funName : "get + funName" is the name of the getter. "set + funName" is the name of the setter. @warning : The getter and setter are public virtual functions, you should rewrite them first. The variables and methods declared after CC_PROPERTY are all public. If you need protected or private, please declare. */#define CC_PROPERTY(varType, varName, funName)\protected: varType varName;\public: virtual varType get##funName(void);\public: virtual void set##funName(varType var);
CC_PROPERTY使用方法:
.h
#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"USING_NS_CC;using namespace std;class HelloWorld : public CCLayer{public: virtual bool init(); static CCScene* scene(); CREATE_FUNC(HelloWorld); CC_PROPERTY(unsigned int, _heroID, HeroID); CC_PROPERTY(string, _heroName, HeroName);};#endif // __HELLOWORLD_SCENE_H__
.cpp
#include "HelloWorldScene.h"#include "SimpleAudioEngine.h"using namespace cocos2d;using namespace CocosDenshion;CCScene* HelloWorld::scene(){ CCScene *scene = CCScene::create(); HelloWorld *layer = HelloWorld::create(); scene->addChild(layer); return scene;}// on "init" you need to initialize your instancebool HelloWorld::init(){ if ( !CCLayer::init() ) { return false; } this->setHeroID(110120); this->setHeroName("police doctor"); CCLog("HeroID == %d, HeroName == %s",this->getHeroID(),this->getHeroName().c_str()); return true;}//CC_PROPERTY(unsigned int, _heroID, HeroID);void HelloWorld::setHeroID(unsigned int var){ _heroID = var;}unsigned int HelloWorld::getHeroID(){ return _heroID;}//CC_PROPERTY(string, _heroName, HeroName);void HelloWorld::setHeroName(string var){ _heroName = var;}string HelloWorld::getHeroName(){ return _heroName;}
0 0
- cocos2dx 宏:CC_PROPERTY
- 宏:CC_PROPERTY
- cocos2d-x中的宏定义CC_PROPERTY
- cocos2d-x CC_PROPERTY 和 CC_SYNTHESIZE_READONLY 区别
- cocos2dx 宏
- cocos2dx常用宏命令
- cocos2dx iOS 宏
- cocos2dx常用宏
- cocos2dx 关于CREATE_FUNC 宏
- cocos2dx
- cocos2dx
- cocos2dx
- cocos2dx
- cocos2dx
- cocos2dx
- Cocos2dx
- cocos2dx
- cocos2dx
- 我们约好的
- .NET的一些指令
- Java Collection 迭代器
- 程序员的练级之路--只读后感
- ACCESS数据库程序设计
- cocos2dx 宏:CC_PROPERTY
- oracle 体系结构
- Linux Slub分配器(二)--初始化 .
- asp.net MVC学习手记2:Spring.Net部分高大上
- 数据结构 - 树形选择排序 (tree selection sort) 详解 及 代码(C++)
- Android中如何像 360 一样优雅的杀死后台服务而不启动
- MYSQL如何计算两个日期间隔天数
- hadoop 技术学习记录(一)
- 强大的心理定律