@@ -174,6 +174,8 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
174174 _scheduler :null ,
175175
176176 _initializedNode :false ,
177+ _additionalTransformDirty :false ,
178+ _additionalTransform :null ,
177179
178180 /**
179181 * Constructor
@@ -201,6 +203,8 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
201203 return this . _scheduler ;
202204 } ;
203205 this . _initializedNode = true ;
206+ this . _additionalTransform = cc . AffineTransformMakeIdentity ( ) ;
207+ this . _additionalTransformDirty = false ;
204208 } ,
205209
206210 init :function ( ) {
@@ -1696,11 +1700,67 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
16961700 t . tx += this . _anchorPointInPoints . x ;
16971701 t . ty += this . _anchorPointInPoints . y ;
16981702 }
1703+ if ( this . _additionalTransformDirty ) {
1704+ this . _transform = cc . AffineTransformConcat ( this . _transform , this . _additionalTransform ) ;
1705+ this . _additionalTransformDirty = false ;
1706+ }
16991707 this . _transformDirty = false ;
17001708 }
17011709 return this . _transform ;
17021710 } ,
17031711
1712+ /**
1713+ *<p> Sets the additional transform.<br/>
1714+ * The additional transform will be concatenated at the end of nodeToParentTransform.<br/>
1715+ * It could be used to simulate `parent-child` relationship between two nodes (e.g. one is in BatchNode, another isn't).<br/>
1716+ * // create a batchNode<br/>
1717+ * var batch= cc.SpriteBatchNode.create("Icon-114.png");<br/>
1718+ * this.addChild(batch);<br/>
1719+ *<br/>
1720+ * // create two sprites, spriteA will be added to batchNode, they are using different textures.<br/>
1721+ * var spriteA = cc.Sprite.createWithTexture(batch->getTexture());<br/>
1722+ * var spriteB = cc.Sprite.create("Icon-72.png");<br/>
1723+ *<br/>
1724+ * batch.addChild(spriteA);<br/>
1725+ *<br/>
1726+ * // We can't make spriteB as spriteA's child since they use different textures. So just add it to layer.<br/>
1727+ * // But we want to simulate `parent-child` relationship for these two node.<br/>
1728+ * this.addChild(spriteB);<br/>
1729+ *<br/>
1730+ * //position<br/>
1731+ * spriteA.setPosition(ccp(200, 200));<br/>
1732+ *<br/>
1733+ * // Gets the spriteA's transform.<br/>
1734+ * var t = spriteA.nodeToParentTransform();<br/>
1735+ *<br/>
1736+ * // Sets the additional transform to spriteB, spriteB's postion will based on its pseudo parent i.e. spriteA. <br/>
1737+ * spriteB.setAdditionalTransform(t);<br/>
1738+ *<br/>
1739+ * //scale<br/>
1740+ * spriteA.setScale(2);<br/>
1741+ *<br/>
1742+ // Gets the spriteA's transform.<br/>
1743+ * * t = spriteA.nodeToParentTransform();<br/>
1744+ *<br/>
1745+ * // Sets the additional transform to spriteB, spriteB's scale will based on its pseudo parent i.e. spriteA. <br/>
1746+ * spriteB.setAdditionalTransform(t);<br/>
1747+ *<br/>
1748+ * //rotation<br/>
1749+ * spriteA.setRotation(20);<br/>
1750+ *<br/>
1751+ * // Gets the spriteA's transform.<br/>
1752+ * t = spriteA.nodeToParentTransform();<br/>
1753+ *<br/>
1754+ * // Sets the additional transform to spriteB, spriteB's rotation will based on its pseudo parent i.e. spriteA. <br/>
1755+ * spriteB.setAdditionalTransform(t);<br/>
1756+ </p>
1757+ */
1758+ setAdditionalTransform :function ( additionalTransform ) {
1759+ this . _additionalTransform = additionalTransform ;
1760+ this . _transformDirty = true ;
1761+ this . _additionalTransformDirty = true ;
1762+ } ,
1763+
17041764 /**
17051765 * Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.<br/>
17061766 * The matrix is in Pixels.
0 commit comments