使用 sprite 套件游戏覆盖功能

Override function with sprite kit game

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

如果当用户将手指从屏幕上移开时球必须停止,您可能想要 use:

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
}

this如果您需要知道触摸何时中断:

    override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
}