fre*_*dnd 8 touch ios uitapgesturerecognizer scenekit swift
我创建了一个游戏SceneKit scene成UIViewController.
我实现了UITapGestureRecognizer这样的:
// TAP GESTURE
let tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")
sceneView.overlaySKScene?.view!.addGestureRecognizer(tapGesture)
Run Code Online (Sandbox Code Playgroud)
而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
}
}
}
Run Code Online (Sandbox Code Playgroud)
想象一下,myNode这个位置是(x: 150.0, y: 150.0).问题在于它与'sy位置' touchPosition.y的y位置相反myNode.
如何反转触摸的y位置?
谢谢 !
Rac*_*hel 11
试试这个,它对我来说很准确: -
override func didMoveToView(view: SKView) {
let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("tap:"))
tap.numberOfTapsRequired = 1
view.addGestureRecognizer(tap)
}
func tap(sender:UITapGestureRecognizer){
if sender.state == .Ended {
var touchLocation: CGPoint = sender.locationInView(sender.view)
touchLocation = self.convertPointFromView(touchLocation)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6112 次 |
| 最近记录: |