Add CCRemoveSelf Action

This commit is contained in:
waiter 2013-03-25 18:18:38 +08:00
parent f6742c3bcd
commit af9e3442c6
2 changed files with 16 additions and 7 deletions

View File

@ -191,24 +191,29 @@ CCObject* CCToggleVisibility::copyWithZone(CCZone *pZone)
// //
// Remove Self // Remove Self
// //
CCRemoveSelf * CCRemoveSelf::create() CCRemoveSelf * CCRemoveSelf::create(bool isNeedCleanUp /*= true*/)
{ {
CCRemoveSelf *pRet = new CCRemoveSelf(); CCRemoveSelf *pRet = new CCRemoveSelf();
if (pRet) { if (pRet && pRet->init(isNeedCleanUp)) {
pRet->autorelease(); pRet->autorelease();
} }
return pRet; return pRet;
} }
bool CCRemoveSelf::init(bool isNeedCleanUp) {
m_bIsNeedCleanUp = isNeedCleanUp;
return true;
}
void CCRemoveSelf::update(float time) { void CCRemoveSelf::update(float time) {
CC_UNUSED_PARAM(time); CC_UNUSED_PARAM(time);
m_pTarget->removeFromParentAndCleanup(true); m_pTarget->removeFromParentAndCleanup(m_bIsNeedCleanUp);
} }
CCFiniteTimeAction *CCRemoveSelf::reverse() { CCFiniteTimeAction *CCRemoveSelf::reverse() {
return (CCFiniteTimeAction*) (CCRemoveSelf::create()); return (CCFiniteTimeAction*) (CCRemoveSelf::create(m_bIsNeedCleanUp));
} }
CCObject* CCRemoveSelf::copyWithZone(CCZone *pZone) { CCObject* CCRemoveSelf::copyWithZone(CCZone *pZone) {
@ -223,6 +228,7 @@ CCObject* CCRemoveSelf::copyWithZone(CCZone *pZone) {
} }
CCActionInstant::copyWithZone(pZone); CCActionInstant::copyWithZone(pZone);
pRet->init(m_bIsNeedCleanUp);
CC_SAFE_DELETE(pNewZone); CC_SAFE_DELETE(pNewZone);
return pRet; return pRet;
} }

View File

@ -122,9 +122,12 @@ public:
virtual CCFiniteTimeAction * reverse(void); virtual CCFiniteTimeAction * reverse(void);
virtual CCObject* copyWithZone(CCZone *pZone); virtual CCObject* copyWithZone(CCZone *pZone);
public: public:
/** create the action */
/** Allocates and initializes the action */ static CCRemoveSelf * create(bool isNeedCleanUp = true);
static CCRemoveSelf * create(); /** init the action */
bool init(bool isNeedCleanUp);
protected:
bool m_bIsNeedCleanUp;
}; };
/** /**