Alex Honcharuk
Alex Honcharuk

Reputation: 23

iPhone, cocos2d coordinate system

I've created CocosNode, then inserted sprite in this node. I moved node and sprite separately. As result node has some coordinate, sprite has another coordinate. I see sprite on the screen, but sprite's coordinates are out of the screen borders.

So could you please explain how can I convert sprite coordinates to screen coordinates?

Thanks.

Upvotes: 3

Views: 7513

Answers (1)

CJ Hanson
CJ Hanson

Reputation: 833

Cocos provides methods for this. To convert from your node's position to world space (cocos coord system, y increases toward the top of the screen) you would do:

[aSprite convertToWorldSpace:aSprite.position];

To convert from this coord system to iPhone view coord system (y increases toward the bottom of the screen) do:

[[CCDirector sharedDirector] convertToGL:[aSprite convertToWorldSpace:aSprite.position]];

Upvotes: 6

Related Questions