我正在从swift 1迁移我的游戏,我无法弄清楚如何修复此功能。我试图检测是否没有发生接触,这应该保持球不动。这是我的代码并且不断收到错误touchesBegan的重新声明无效。我不知道如何解决这个问题,我已经被困了一段时间,并且当没有接触时不能让球停止移动。请帮助,谢谢
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
// do nothing if ad is showing
if Ad.share().showing {
return
}
let touch = touches.first! as UITouch
let touchedLocation = touch.locationInNode(self)
// change the speedXFirst of the ball if it starts
if start {
// start move
let moveRight = touchedLocation.x > CGRectGetMidX(self.frame)
let speedX = moveRight ? ballSpeedX : -ballSpeedX
ball.speedXFirst = speedX
}
// start game if it stops
else {
startGame()
}
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { //error RIGHT HERE
if start {
// stop move
ball.speedXFirst = 0
}