1
votes

I tried to get real coordinates (like on iPad screen) for all elements on active scene using

CCARRAY_FOREACH(node->getChildren(), obj)

for each Node I tried

CCPoint realCoordinates = node->getParent()->convertToWorldSpace(node->getPosition());

or this

CCPoint realCoordinates = node->convertToWorldSpace(node->getPosition());

or

CCPoint realCoordinates = node->convertToWorldSpaceAR(CCPointZero);

In result: For some node from my elements tree I have wrong coordinates.

Element tree is big in deep nested with anchors.

May be somthing can help me how can I calculate valid absolute (1024х768) screen coordinates for all elements from my CCNode tree.

Thanks

1
You should rather call obj->getParent()->convertToNodeSpace(obj->getPosition()) rather than node->getParent()->convertToWorldSpace() - Nadarian
node->getParent()->convertToWorldSpace(node->getPosition()) should work. It does for me. - Guy Kogus
Maybe you lastly want to call CCDirector::sharedDirector()->convertToUI(realCoordinates) to get it in screen coordinates? - Guy Kogus

1 Answers

1
votes

The solution is

node->getParent()->convertToWorldSpace(node->getPosition())

This worked for me for a button as a child of a listview in a child of a layout in the scene.

Seems like it should be working with you, too.