From a70569ff03f12a999a15ba8228a5c927a25bc151 Mon Sep 17 00:00:00 2001 From: Lucian Varlan Date: Mon, 27 May 2013 15:46:15 +0300 Subject: [PATCH] OnEnterTransitionDidFinish was called twice when a node is added in onEnter Fix ported from cocos2d-iphone: https://github.com/cocos2d/cocos2d-iphone/commit/99b7bef8800bd850f6b0c7dc1eb09d8e81fd80f7 --- cocos2dx/base_nodes/CCNode.cpp | 10 +++++++++- cocos2dx/base_nodes/CCNode.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index 19b1c1239a..f7750540e0 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -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) diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index 75c72dc59b..90699531eb 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -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.