Get node position in global coordinates

Can I do the following for a Node* node with a single method. I couldn’t find any method for cocos2d::Node API.

node->getParent()->convertToWorldSpace(node->getPosition());
node->convertToWorldSpace(Vec2::ZERO);

@mausmausgames

I have tested it is not equivalent, though looks to be a correct approach.

Are you sure this is equivalent in case there is a scale or skew or some other thing applied? At least I can point out one important difference - if node does not have a parent you cannot do the first one I have written, but you can do what you have suggested.

I guess anchor point is also important here. The anchor point should be Vec2::ANCHOR_BOTTOM_LEFT I think for your code.

You’re right, my mistake.

You have to use the anchor related version.

node->convertToWorldSpaceAR(Vec2::ZERO);
1 Like