SpriteKit - 更改 SKReferenceNode 坐标系

SpriteKit - Change SKReferenceNode coordinate system

我目前正在 SpriteKit 中的 2D 无尽奔跑者中工作。我使用场景编辑器创建新的关卡序列,然后将它们作为 SKReferenceNode 添加到主场景。

问题是,我需要获取 SKReferenceNode 中单个节点的位置,但我得到的是相对于 SKReferenceNodes 坐标系而不是主坐标系的。

如何获取节点相对于主场景的位置?

您需要使用转换函数

func convert(_ point: CGPoint, to node: SKNode) -> CGPoint

Description
Converts a point in this node’s coordinate system to the coordinate system of another node in the node tree.

Parameters
point - A point in this node’s coordinate system.

node - Another node in the same node tree as this node.

Returns
The same point converted to the other node’s coordinate system.