[转]CCLayer相关资料

转自:http://blog.csdn.net/kennyliang123/article/details/7957458

cocos2d-x给CCLayer的子类提供了2个宏,这两个宏用来生成CCLayer的node方法

#define LAYER_NODE_FUNC(layer) 这个宏生成的node方法是不带参数的,需要子类有一个没有参数的init()方法

#define LAYER_NODE_FUNC_PARAM(layer,__PARAMTYPE__,__PARAM__) 这个宏生成的node方法带参数,需要子类有一个带相同参数的init方法

[plain] view plain copy
  1. class BackgroundLayer:public CCLayer  
  2. {  
  3. public:  
  4.     LAYER_NODE_FUNC(BackgroundLayer);  
  5.     LAYER_NODE_FUNC_PARAM(BackgroundLayer, CCString*, id);  
  6.     virtual bool init();  
  7.     virtual bool init(CCString* id);  
  8. };  


使用:

[plain] view plain copy
    1. backgroundLayer = BackgroundLayer::node();  
    2. this->addChild(backgroundLayer);  
    3.       
    4. backgroundLayer = BackgroundLayer::node(m_scnID);  
    5. this->addChild(backgroundLayer); 

你可能感兴趣的:(c)