From ed4e288f2759d7690f46847ce6ac1474b19009d3 Mon Sep 17 00:00:00 2001 From: Walzer Date: Fri, 1 Oct 2010 15:04:12 +0000 Subject: [PATCH] modify the logic of "node" method --- .../CCLayer.cpp | 55 ++++++++++--------- .../CCScene.cpp | 15 +++-- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index 509f7a4e73..d2cf7a6c2c 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -27,7 +27,7 @@ THE SOFTWARE. #include "CCTouchDispatcher.h" #include "CCDirector.h" #include "CGPointExtension.h" -namespace cocos2d { +namespace cocos2d { // CCLayer CCLayer::CCLayer() @@ -43,30 +43,33 @@ CCLayer::~CCLayer() { } -bool CCLayer::init() -{ - bool bRet = false; - do - { - CCDirector * pDirector; - CCX_BREAK_IF( ! (pDirector = CCDirector::getSharedDirector()) ); - this->setContentSize(pDirector->getWinSize()); - // success - bRet = true; - } while (0); - return bRet; -} - -CCLayer *CCLayer::node() -{ - CCLayer *pRet = new CCLayer(); - if (pRet && pRet->init()) - { - pRet->autorelease(); - return pRet; - } - CCX_SAFE_DELETE(pRet) - return NULL; +bool CCLayer::init() +{ + bool bRet = false; + do + { + CCDirector * pDirector; + CCX_BREAK_IF( ! (pDirector = CCDirector::getSharedDirector()) ); + this->setContentSize(pDirector->getWinSize()); + // success + bRet = true; + } while (0); + return bRet; +} + +CCLayer *CCLayer::node() +{ + CCLayer *pRet = new CCLayer(); + if (pRet && pRet->init()) + { + pRet->autorelease(); + return pRet; + } + else + { + CCX_SAFE_DELETE(pRet) + return NULL; + } } /// Touch and Accelerometer related @@ -415,4 +418,4 @@ void CCMultiplexLayer::switchToAndReleaseMe(unsigned int n) this->addChild(m_pLayers->getObjectAtIndex(n)); } -}//namespace cocos2d +}//namespace cocos2d diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp index 2291f811b3..916b1752ef 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp @@ -29,10 +29,10 @@ THE SOFTWARE. namespace cocos2d { CCScene::CCScene() -{ - m_bIsRelativeAnchorPoint = false; - m_tAnchorPoint = ccp(0.5f, 0.5f); - m_eSceneType = ccNormalScene; +{ + m_bIsRelativeAnchorPoint = false; + m_tAnchorPoint = ccp(0.5f, 0.5f); + m_eSceneType = ccNormalScene; } CCScene::~CCScene() @@ -61,7 +61,10 @@ CCScene *CCScene::node() pRet->autorelease(); return pRet; } - CCX_SAFE_DELETE(pRet) - return NULL; + else + { + CCX_SAFE_DELETE(pRet) + return NULL; + } } }//namespace cocos2d