5
Ho creato un gioco con un SceneKit scene
in un UIViewController
.Converti touch location di UITapGestureRecognizer per SpriteKit - Swift
ho implementato un UITapGestureRecognizer
come questo:
// TAP GESTURE
let tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")
sceneView.overlaySKScene?.view!.addGestureRecognizer(tapGesture)
E la funzione handleTap
:
func handleTap(sender: UIGestureRecognizer) {
if sender.state == UIGestureRecognizerState.Ended {
var touchLocation = sender.locationInView(sender.view)
touchLocation = self.view.convertPoint(touchLocation, toView: self.view)
let touchedNode = sceneView.overlaySKScene?.nodeAtPoint(touchLocation)
if touchedNode == myNode {
// DO SOMETHING
}
}
}
Immaginate che la posizione myNode
s' è (x: 150.0, y: 150.0)
. Il problema è che lo touchPosition.y
si trova al contrario della posizione y della posizione myNode
.
Come si inverte la posizione del tocco?
Grazie!
Dove è l'attuazione di convertPointFromView? –
questo metodo override didMovetoView non è chiamato nella mia classe UIviewcontroller. perché? – Hitesh