Would you like to talk to me about convertTo method in CCNode?


#1

I want to picking sprite in my map.
I Just know picking is skill that monitor position with a sprite position.

I got a lot of time. but my head was burnning.

CCPoint convertToNodeSpace (const CCPoint &worldPoint)
Converts a Point to node (local) space coordinates.
CCPoint convertToWorldSpace (const CCPoint &nodePoint)
Converts a Point to world space coordinates.
CCPoint convertToNodeSpaceAR (const CCPoint &worldPoint)
Converts a Point to node (local) space coordinates.
CCPoint convertToWorldSpaceAR (const CCPoint &nodePoint)
Converts a local Point to world space coordinates.The result is in Points.
CCPoint convertTouchToNodeSpace (CCTouch *touch)
convenience methods which take a CCTouch instead of CCPoint
CCPoint convertTouchToNodeSpaceAR (CCTouch *touch)
converts a CCTouch (world coordinates) into a local coordiante.

please help me. What is world coordinates and local coordinates conception. or sites.


#2

Is this image helpful? OpenGL coordination is different from Touch coordination.


#3

convertToWorldSpace(const CCPoint& nodePoint) converts on-node coords to SCREEN coordinates.
Lets we have layerA with anchor point and position (0,0) attached to screen and have a sprite on this layer at point (100, 100).
What will be SCREEN coords of sprite? - (100, 100)

Lets we moved layerA to point (- 50, - 20). What will be SCREEN coords of sprite? - (100 - 50, 100 - 20), i.e. (50, 80) - that’s what convertToWorldSpace returns to us if we call layerA~~>convertToWorldSpace).
The same is applied when you scale layerA~~ i.e. convertToWorldSpace will always return SCREEN position of our sprite, might be very useful if you want to capture taps on your sprite but need to move/scale your layerA.

As for convertToWorldSpaceAR - will return the position relatevely to anchor point: so if our scene - root layer has AP (0.5f, 0.5f) - default, convertToWorldSpaceAR should return position relatively to screen center. I have not used it.

convertToNodeSpace(const CCPoint& worldPoint) - converts SCREEN coords to NODE’s local. I.e. if for our example with moved layer call:
layerA~~>convertToNodeSpace)~~ that should return (100, 100) - our sprite on-node coords.

convertToNodeSpaceAR - the same logic as for convertToWorldSpaceAR.

Alex


#4

so WorldSpace means screen coords.
Thank you. very much.