我正在从 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
}