Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding absolute position of child SKNode?

I have an SKSpriteNode that is parented to (i.e. a child of) a scrolling background. The SKSpriteNode does not move itself, it just moves along with the scrolling background. What is the best way to find the absolute position of the SKSpriteNode as the background moves.

like image 336
fuzzygoat Avatar asked Feb 18 '14 12:02

fuzzygoat


1 Answers

CGPoint positionInScene = [self.scene convertPoint:self.position 
                                                  fromNode:self.parent];

However, convertPoint:fromNode: is pretty expensive, especially if you use it in update method. I'd rather just add childNode's x position to parentNode's x position:

CGFloat xPosition = self.position.x + self.parent.position.x;
like image 179
Andrey Gordeev Avatar answered Sep 21 '22 13:09

Andrey Gordeev