ConvertToWorldSpace - cocos2d

  • convertToWorldSpace

Hi, I'm not sure I understand how this works. Api claims that it will convert the local coordinate into world space.

Say I have three sprites. spriteA is added to the scene, and spriteB is added to spriteA. And spriteC is added to spriteB.

- Scene - spriteA - spriteB - spriteC 

And I want to convert the spriteC source to the world

If I do: [self convertToWorldSpace:[spriteC CGPointZero]];

or this: [spriteA convertToWorldSpace:[spriteC CGPointZero]];

or this: [spriteB convertToWorldSpace:[spriteC CGPointZero]];

or even [spriteC convertToWorldSpace:[spriteC CGPointZero]];

Don't they all give the same answer, since they all transform into world coordinates? Or am I moving from one node space to the parent node space ... until I get to world space.

What is the correct answer to see the position of spriteC in world coordinates?

+7
source share
3 answers

To find the origin of world space on spriteC , you take the sprite parent, in this case spriteB and query the world space of your child:

 [spriteB convertToWorldSpace:[spriteC CGPointZero]]; 
+4
source
 [spriteC convertToWorldSpace:CGPointZero]; 

As the answer is Kazuki, but CGPointZero is global.

+1
source
 [spriteC convertToWorldSpace:[spriteC CGPointZero]]; 

convertToWorldSpace: the method converts one node space to the parent node space ... until it falls into world space.

0
source

All Articles