7
votes
  • convertToWorldSpace

Hi, I'm not sure I understand how this works. The api states that it converts local coordinate to world space.

Let' say I have three sprites. spriteA added to scene , and spriteB added to spriteA. And spriteC added to spriteB.

- Scene
    - spriteA
        - spriteB
            - spriteC

And I want to convert spriteC origin to 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]];

Shouldn't they all give the same answer since they are all transformed to world coordinates? Or do I go from one node space to parent node space ...until I get to world space.

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

3

3 Answers

4
votes

To find the world space origin on spriteC, you take the sprites parent, in this case spriteB and ask for the world space of its child:

[spriteB convertToWorldSpace:[spriteC CGPointZero]];
1
votes
[spriteC convertToWorldSpace:CGPointZero];

As Kazuki answer but CGPointZero is a global.

0
votes
[spriteC convertToWorldSpace:[spriteC CGPointZero]];

convertToWorldSpace: method converts one node space to parent node space ... until it gets to world space.