OnEnterTransitionDidFinish was called twice when a node is added in onEnter

Fix ported from cocos2d-iphone:
99b7bef880
This commit is contained in:
Lucian Varlan 2013-05-27 15:46:15 +03:00
parent 9f45c23222
commit a70569ff03
2 changed files with 10 additions and 1 deletions

View File

@ -86,6 +86,7 @@ CCNode::CCNode(void)
, m_bVisible(true)
, m_bIgnoreAnchorPointForPosition(false)
, m_bReorderChildDirty(false)
, m_bIsTransitionFinished(false)
, m_nScriptHandler(0)
, m_nUpdateScriptHandler(0)
{
@ -597,7 +598,10 @@ void CCNode::addChild(CCNode *child, int zOrder, int tag)
if( m_bRunning )
{
child->onEnter();
child->onEnterTransitionDidFinish();
// prevent onEnterTransitionDidFinish to be called twice when a node is added in onEnter
if (m_bIsTransitionFinished) {
child->onEnterTransitionDidFinish();
}
}
}
@ -895,6 +899,8 @@ void CCNode::transform()
void CCNode::onEnter()
{
m_bIsTransitionFinished = false;
arrayMakeObjectsPerformSelector(m_pChildren, onEnter, CCNode*);
this->resumeSchedulerAndActions();
@ -909,6 +915,8 @@ void CCNode::onEnter()
void CCNode::onEnterTransitionDidFinish()
{
m_bIsTransitionFinished = true;
arrayMakeObjectsPerformSelector(m_pChildren, onEnterTransitionDidFinish, CCNode*);
if (m_eScriptType == kScriptTypeJavascript)

View File

@ -1372,6 +1372,7 @@ protected:
///< Used by CCLayer and CCScene.
bool m_bReorderChildDirty; ///< children order dirty flag
bool m_bIsTransitionFinished; ///< flag to indicate whether the transition was finished
int m_nScriptHandler; ///< script handler for onEnter() & onExit(), used in Javascript binding and Lua binding.
int m_nUpdateScriptHandler; ///< script handler for update() callback per frame, which is invoked from lua & javascript.