常見宏
1)NS_CC_BEGIN cocos2d命名空間開始
2) NS_CC_END cocos2d命名空間結束
3)USING_NS_CC 聲明cocos2d命名空間
4)CC_SYNTHESIZE_READONLY(varType, varName, funName)聲明一個成員變數以及getfunName函數,沒有set函數。getfunName已經實現,其實現就是返回這個值。
/** CC_SYNTHESIZE_READONLY is used to declare a protected variable. We can use getter to read the variable. @param varType : the type of variable. @param varName : variable name. @param funName : "get + funName" is the name of the getter. @warning : The getter is a public inline function. The variables and methods declared after CC_SYNTHESIZE_READONLY are all public. If you need protected or private, please declare. */#define CC_SYNTHESIZE_READONLY(varType, varName, funName)\protected: varType varName;\public: virtual varType get##funName(void) const { return varName; }#define CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void) const { return varName; }
5)CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName) 類似CC_SYNTHESIZE_READONLY,不過getfunName返回的是引用。
#define CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void) const { return varName; }
6)CC_SYNTHESIZE(varType, varName, funName) 聲明一個成員變數以及getfunName,setfunName函數.函式宣告和實現都有。
/** CC_SYNTHESIZE 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 inline functions. The variables and methods declared after CC_SYNTHESIZE are all public. If you need protected or private, please declare. */#define CC_SYNTHESIZE(varType, varName, funName)\protected: varType varName;\public: virtual varType get##funName(void) const { return varName; }\public: virtual void set##funName(varType var){ varName = var; }
7)CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName) 類似CC_SYNTHESIZE,不過getfunName返回的是引用。
#define CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void) const { return varName; }\public: virtual void set##funName(const varType& var){ varName = var; }
8)CC_PROPERTY_READONLY(varType, varName, funName) 聲明一個成員變數以及getfunName函數,沒有set函數。getfunName函數的實現要自己實現。
/** CC_PROPERTY_READONLY is used to declare a protected variable. We can use getter to read the variable. @param varType : the type of variable. @param varName : variable name. @param funName : "get + funName" is the name of the getter. @warning : The getter is a public virtual function, you should rewrite it first. The variables and methods declared after CC_PROPERTY_READONLY are all public. If you need protected or private, please declare. */#define CC_PROPERTY_READONLY(varType, varName, funName)\protected: varType varName;\public: virtual varType get##funName(void);
9)CC_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName) 類似CC_PROPERTY_READONLY,不過getfunName返回的是引用。getfunName函數的實現要自己實現。
#define CC_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void);
10)CC_PROPERTY(varType, varName, funName) 聲明一個成員變數以及getfunName,setfunName函數.函數實現要自己實現。
/** 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);
11)CC_PROPERTY_PASS_BY_REF(varType, varName, funName) 類似CC_PROPERTY,,不過getfunName返回的是引用
#define CC_PROPERTY_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void);\public: virtual void set##funName(const varType& var);