newlist

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#ifndef __CCCONTROLSCENE_H__
#define __CCCONTROLSCENE_H__

#include "cocos2d.h"
#include "cocos-ext.h"


USING_NS_CC;
USING_NS_CC_EXT;
//创建层的同时赋值标题
#define CONTROL_SCENE_CREATE_FUNC(controlScene) \
public: \
static CCScene* sceneWithTitle(const char * title) \
{ \
    CCScene* pScene = CCScene::create(); \
    controlScene* controlLayer = new controlScene(); \
    if (controlLayer && controlLayer->init()) \
    { \
        controlLayer->autorelease(); \
        controlLayer->getSceneTitleLabel()->setString(title); \
        pScene->addChild(controlLayer); \
    } \
    else \
    { \
        CC_SAFE_DELETE(controlLayer); \
    } \
    return pScene; \
}

//创建访问器,get和set
#define CC_SYNTHESIZE_RETAIN(varType, varName, funName)    \
private: varType varName; \
public: virtual varType get##funName(void) const { return varName; } \
public: virtual void set##funName(varType var)   \
{ \
    if (varName != var) \
    { \
        CC_SAFE_RETAIN(var); \
        CC_SAFE_RELEASE(varName); \
        varName = var; \
    } \
} 

class CCControlScene : public CCLayer
{
public:
    CCControlScene();
    ~CCControlScene();
    bool init();
    // Menu Callbacks
    void toExtensionsMainLayer(CCObject* sender);
    void previousCallback(CCObject* sender);
    void restartCallback(CCObject* sender);
    void nextCallback(CCObject* sender);

    /** Title label of the scene. */
    CC_SYNTHESIZE_RETAIN(CCLabelTTF*, m_pSceneTitleLabel, SceneTitleLabel)

    CONTROL_SCENE_CREATE_FUNC(CCControlScene);
};

#endif /* __CCCONTROLSCENE_H__ */
//删除指针,并赋值为空
#define CC_SAFE_RELEASE_NULL(p)        do { if(p) { (p)->release(); (p) = 0; } } while(0)

CCControlScene::~CCControlScene()
{
    CC_SAFE_RELEASE_NULL(m_pSceneTitleLabel);
}

 

posted on 2013-08-07 17:01  一枚程序  阅读(423)  评论(0编辑  收藏  举报