我正在尋找一個問題,我一直堅持一段時間,但無法找到答案的幫助。如何防止額外的觸摸干擾拖動位置
我有一個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