SpriteA is at (100,100)
SpriteB is child of SpriteA and is at (50,0)
I want to get the position of SpriteB. If I do GetPosition() on it I just get (50,0) as expected but I want to get (150,100) back somehow. The reason I can’t just do the simple math is that SpriteA will scale and rotate which makes the math more complex.
Is there a way to get actual position of SpriteB in the scene?
You can get the real position of SpriteB like this:
SpriteB->convertToWorldSpace(SpriteB->getPosition());
1 Like
Thank you! Did you have a typo? I got the results by doing…
SpriteA->convertToWorldSpace(SpriteB->getPosition());
not
SpriteB->convertToWorldSpace(SpriteB->getPosition());
Also, is there a way to do the reverse? For instance, Convert a world coordinate to a coordinate relative to a parent?
1 Like
It depends what you want.
The reverse way is convertToNodeSpace().
Dear Zhangxm,
can u help me how to change the position of two sprites while drag and drop .
I created two Sprites…like this
CCSprite *splash=CCSprite::create(“Level3.png”);
splash->setPosition(ccp(200,500));
this->addChild(splash,1);
CCSprite *spla=CCSprite::create("Level4.png");
spla->setPosition(ccp(300,500));
this->addChild(spla,1);
now i have to swap it…i posted this thing so many portals till now not get any updates at-least you can help me i feel as soon as possible