をUIView
とSKNode
に変換したいのですが、convert(_:to/from:)
メソッドでビュー/レイヤーを変換する方法と同様です。UIViewsとSKNodes間のポイントを変換する方法
これを行う正しい方法は何ですか?
このように使用extension SKNode {
/// Find point in node relative to it's containing SKView
/// so that it can be further converted relative to other views.
func pointInContainingView(_ point:CGPoint) -> (SKView, CGPoint)? {
guard let scene = scene, let view = scene.view else {
return nil
}
// Invert Y to match view coordinate system.
let invertedY = CGPoint(x: point.x, y: -point.y)
// Get the point in it's containing scene.
let pointInScene = convert(invertedY, from: scene)
// Get the resulting point in the containing SKView
let pointInView = view.convert(pointInScene, from: scene)
return (view, pointInView)
}
}
:ここ