Projects > cpp > Issues > Feature #1743

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Adding an additional transform for CCNode.

Feature #1743 [Closed]
dumganhar 2013-02-22 08:01 . Updated almost 4 years ago

The additional transform will be concatenated at the end of nodeToParentTransform.
It could be used to simulate `parent-child` relationship between two nodes (e.g. one is in BatchNode, another isn’t).

        // create a batchNode
        CCSpriteBatchNode* batch= CCSpriteBatchNode::create("Icon-114.png");
        this->addChild(batch);

        // create two sprites, spriteA will be added to batchNode, they are using different textures.
        CCSprite* spriteA = CCSprite::createWithTexture(batch->getTexture());
        CCSprite* spriteB = CCSprite::create("Icon-72.png");

        batch->addChild(spriteA); 

        // We can't make spriteB as spriteA's child since they use different textures. So just add it to layer.
        // But we want to simulate `parent-child` relationship for these two node.
        this->addChild(spriteB); 

        //position
        spriteA->setPosition(ccp(200, 200));

        // Gets the spriteA's transform.
        CCAffineTransform t = spriteA->nodeToParentTransform();

        // Sets the additional transform to spriteB, spriteB's postion will based on its pseudo parent i.e. spriteA.
        spriteB->setAdditionalTransform(t);

        //scale
        spriteA->setScale(2);

        // Gets the spriteA's transform.
        t = spriteA->nodeToParentTransform();

        // Sets the additional transform to spriteB, spriteB's scale will based on its pseudo parent i.e. spriteA.
        spriteB->setAdditionalTransform(t);

        //rotation
        spriteA->setRotation(20);

        // Gets the spriteA's transform.
        t = spriteA->nodeToParentTransform();

        // Sets the additional transform to spriteB, spriteB's rotation will based on its pseudo parent i.e. spriteA.
        spriteB->setAdditionalTransform(t);
dumganhar 2013-02-22 08:43
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:f7e53f43773e970c65162774bb0c699751b88025.

Atom PDF

Status:Closed
Start date:2013-02-22
Priority:Normal
Due date:
Assignee:dumganhar
% Done:

100%

Category:all
Target version:cocos2d-2.1rc0-x-2.1.2

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.