I am a little confused by how the SKNode
methods convertPoint:fromNode:
and convertPoint:ToNode:
are working, I have looked at the docs but its not that obvious what they do. For example, this (see diagram below) is a small test I did using convertPoint:fromNode:
The black area is the SKScene
background, the blue area is an SKSpriteNode
parented to the SKScene
, the red area is another SKSpriteNode
parented to the blue sprite. The anchor points for both sprites are shown by the small green dots. What I wanted to do was get the scene position for the red sprite, which I did using the following code:
CGPoint positionInScene = [self convertPoint:[self position]
fromNode:[self redSprite]];
The result from this is
positionInScene = [105, 205]
Which is what I expected, as that would be the origin of the red square in scene space. What I am confused about is the arguments. From what I can guess:
[SKNode_A convertPoint: CGPoint_B toNode: SKScene_C]
- SKNode_A = The node coordinate space to convert to ...
- CGPoint_B = The point to convert (not sure why its [self position] above)
- SKNode_C = The node coordinate space to convert from ...
My initial try at this was [self convertPoint:[redSprite position] fromNode:redSprite]
because I was wanting to convert the red sprites origin to the scene. It just seems a bit clunky to get your head round, if anyone can cast a little light & logic on both this and its friend convertPoint:toNode:
it would be very much appreciated.
[self convertPoint:[self position] fromNode:[self redSprite]]
? Is it belongs to the Scene? – Andrey Gordeev