issue #157 retain & release

This commit is contained in:
Walzer 2010-10-13 09:02:48 +00:00
parent 9535831c85
commit ea4ea4b5a2
2 changed files with 19 additions and 17 deletions

View File

@ -16,6 +16,7 @@ bool GameOverScene::init()
if( CCScene::init() )
{
this->_layer = GameOverLayer::node();
_layer->retain(); // notice! in objc it's a property with "retain"
this->addChild(_layer);
return true;
@ -28,8 +29,11 @@ bool GameOverScene::init()
GameOverScene::~GameOverScene()
{
// _layer->release();
// _layer = NULL;
if (_layer)
{
_layer->release();
_layer = NULL;
}
}
//////////////////////////////
@ -39,6 +43,7 @@ bool GameOverLayer::init()
{
CGSize winSize = CCDirector::getSharedDirector()->getWinSize();
this->_label = CCLabel::labelWithString("", "Artial", 32);
_label->retain(); // notice! in objc it's a property with "retain"
_label->setColor( ccc3(0, 0, 0) );
_label->setPosition( ccp(winSize.width/2, winSize.height/2) );
this->addChild(_label);
@ -63,6 +68,9 @@ void GameOverLayer::gameOverDone()
GameOverLayer::~GameOverLayer()
{
// _label->release();
// _label = NULL;
}
if (_label)
{
_label->release();
_label = NULL;
}
}

View File

@ -14,31 +14,25 @@
class GameOverLayer : public cocos2d::CCColorLayer
{
public:
GameOverLayer():_label(NULL) {};
virtual ~GameOverLayer();
bool init();
LAYER_NODE_FUNC(GameOverLayer);
bool init();
void gameOverDone();
inline cocos2d::CCLabel* getLabel() { return _label; };
protected:
cocos2d::CCLabel *_label;
CCX_SYNTHESIZE_READONLY(cocos2d::CCLabel*, _label, Label);
};
class GameOverScene : public cocos2d::CCScene
{
public:
virtual ~GameOverScene();
GameOverScene():_layer(NULL) {};
~GameOverScene();
bool init();
SCENE_NODE_FUNC(GameOverScene);
public:
inline GameOverLayer* getLayer() {return _layer; };
protected:
GameOverLayer *_layer;
CCX_SYNTHESIZE_READONLY(GameOverLayer*, _layer, Layer);
};
#endif // _GAME_OVER_SCENE_H_