Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convertToWorldSpace - cocos2d

  • 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?

like image 453
stone Avatar asked Feb 23 '11 15:02

stone


Video Answer


2 Answers

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]];
like image 157
James Webster Avatar answered Oct 02 '22 13:10

James Webster


[spriteC convertToWorldSpace:CGPointZero];

As Kazuki answer but CGPointZero is a global.

like image 23
Damibu Ltd Avatar answered Oct 02 '22 11:10

Damibu Ltd