我正在寻找一个问题,我一直坚持一段时间,但无法找到答案的帮助。如何防止额外的触摸干扰拖动位置
我有一个SpriteKit儿童游戏应用程序,用户可以在其中围绕屏幕拖动对象(SKspriteNodes)。这是在“触摸”事件,控制,像这样:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
let touch = touches.first as! UITouch
let touchLocation = touch.locationInNode(self)
if piece01.containsPoint(touchLocation) && piece01Placed == false && aPieceIsBeingGrabbed == false {
piece01Grabbed = true
aPieceIsBeingGrabbed = true
self.piece01.zPosition = 4.0
}
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesMoved(touches, withEvent: event)
let touch = touches.first as! UITouch
let touchLocation = touch.locationInNode(self)
if piece01Grabbed && piece01Placed == false {
self.piece01.position = CGPointMake(touchLocation.x + worldScale * 120, touchLocation.y - worldScale * 80)
}
}
我的问题是,如果用户触摸屏幕的另一部分的同时拖动一个精灵,一个毛刺出现和雪碧来回反射两者之间触摸地点,并不能决定哪一个留下来。
有没有人知道我可以如何防止这种情况,让雪碧总是跟随最初被抓住的那种感觉?提前致谢!
我不能为你提供目前一个完整的答案,但我想你指出正确的方向。首先遍历集合中的所有触摸,即触摸触摸{let thisTouch = touch as! UITouch;}'。 UITouch对象持续多点触摸序列。你可以阅读更多关于UITouch对象[这里](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITouch_Class/#//apple_ref/occ/instp/UITouch/gestureRecognizers) – Mason
非常感谢MaceDev ,我现在就研究一下。 – jwade502