5
SceneKit scene
のゲームをUIViewController
に作成しました。SpriteKit - SwiftのUITapGestureRecognizerのタッチ位置を変換する
私はこのようなUITapGestureRecognizer
を実装:
// TAP GESTURE
let tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")
sceneView.overlaySKScene?.view!.addGestureRecognizer(tapGesture)
そして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
}
}
}
はmyNode
の位置が(x: 150.0, y: 150.0)
であることを想像してみてください。 問題はmyNode
のy位置の反対側にtouchPosition.y
があることです。
タッチの位置をどのように反転できますか?
ありがとうございます!
どこconvertPointFromViewの実装はありますか? –
このオーバーライドdidMovetoViewメソッドはMy UIviewcontrollerクラスで呼び出されません。どうして? – Hitesh