我想实现的目标是在屏幕上拖放一个精灵。我尝试了以下代码:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in (touches ) {
let location = touch.locationInNode(self)
if ball.containsPoint(location) {
ball.position = location
}
}
}
这段代码实际可用,但当我快速拖动球时,它检测到“ball”不再包含点“location”,球就停止了,这意味着我需要重新拾起球。我希望球能够迅速响应我的触摸,这样球就不会停止移动。我该怎么做?