From d875edbd745ce3017927a6945b04826b732a732d Mon Sep 17 00:00:00 2001 From: jiang xiaohua Date: Wed, 20 Feb 2013 22:33:28 +0800 Subject: [PATCH] Additional a transformation matrix, Used in is not parent-child relationship but we still need to maintain transformation parent-child Example: GameObject_Parent(CCNode; create from CCNode) GameObject_sub1(CCNode; Create from the same CCSpriteBatchNode,the node's parent is CCLayer ) RenderComponents1( Create form the same CCSpriteBatchNode) Components2 .... GameObject_sub2 (CCNode; Create from the CCNode,the node's parent is GameObject_Parent ) RenderComponents1( not used batchNode) Now, GameObject_sub1 not GameObject_Parent node, but I want it to simulate the change of the son is GameObject_Parent; I Need additional the father's matrix in child Node ; --- cocos2dx/base_nodes/CCNode.cpp | 9 +++++++-- cocos2dx/base_nodes/CCNode.h | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index 638c9dba2b..2ef7d66d36 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -86,6 +86,7 @@ CCNode::CCNode(void) , m_uOrderOfArrival(0) , m_eGLServerState(ccGLServerState(0)) , m_bReorderChildDirty(false) +, m_sOtherTransform(CCAffineTransformMakeIdentity()) { // set default scheduler and actionManager CCDirector *director = CCDirector::sharedDirector(); @@ -1158,13 +1159,17 @@ CCAffineTransform CCNode::nodeToParentTransform(void) m_sTransform = CCAffineTransformTranslate(m_sTransform, -m_obAnchorPointInPoints.x, -m_obAnchorPointInPoints.y); } } - + m_sTransform = CCAffineTransformConcat(m_sTransform, m_sOtherTransform); m_bTransformDirty = false; } return m_sTransform; } - +void CCNode::translateFormOtherNode(CCAffineTransform &transform) +{ + m_sOtherTransform = CCAffineTransformMake(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty); + m_bTransformDirty = true; +} CCAffineTransform CCNode::parentToNodeTransform(void) { if ( m_bInverseDirty ) { diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index daa85b7aa4..83ad2d46a8 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -1256,6 +1256,10 @@ public: */ CCPoint convertTouchToNodeSpaceAR(CCTouch * touch); + /** + * Additional a transformation matrix, Used in is not parent-child relationship but we still need to maintain transformation parent-child + */ + void translateFormOtherNode(CCAffineTransform &transform); /// @} end of Coordinate Converters private: @@ -1290,6 +1294,7 @@ protected: CCSize m_obContentSize; ///< untransformed size of the node + CCAffineTransform m_sOtherTransform;///< transform CCAffineTransform m_sTransform; ///< transform CCAffineTransform m_sInverse; ///< transform