문제

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.

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top