2017-07-22 2 views

Antwort

3

ist, was ich kam mit:

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) 
    } 
} 

wie folgt verwendet:

// view/node 

let origin = node.frame.origin 

if let (nodeView, point) = node.parent?.pointInContainingView(origin) { 
    let converted = nodeView.convert(point, from:view) 
} 
0

Alles, was Sie tun müssen, ist scene.convertPoint(toView:pointOnScene)

Wenn Sie einen Knoten konvertieren, das ist nicht ein Kind der Szene, sondern ein Abkömmling der Szene, Sie tun:

let absolutePosition = node.convert(node.position,toNode:node.scene) 
scene.convertPoint(toView: absolutePosition) 

Eine nette kleine Erweiterung zu verwenden:

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 
     } 
     let pointInView.convertPoint(toView: convert(point,toNode:scene)) 
     return (view, pointInView) 
    } 
} 
Verwandte Themen