且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

父旋转后获取 SpriteKit 节点的可见位置

更新时间:2023-02-01 20:00:20

要获得 SKNode视觉位置,您需要转换它的 .position 在其 .parent 的坐标系中到其 .scene 的坐标系:

To get an SKNode's visual position, you'd want to convert its .position in its .parent's coordinate system to its .scene's coordinate system:

CGPoint vPos = [node.parent convertPoint:node.position toNode:node.scene];

看起来您的第一次尝试 ([_board convertPoint:p toNode:self]) 应该可以工作,只要:

It looks like the first attempt you made ([_board convertPoint:p toNode:self]) should work, as long as:

  1. p 是您在 _board 坐标系中查找的节点内的有效点.
  2. 从您的 SKScene 调用该代码,以便 self 引用节点所在的场景.
  1. p is a valid point inside the node you're looking for in _board's coordinate system.
  2. That code is called from your SKScene so that self references the scene the node is in.