使用精灵套件游戏覆盖功能

时间:2016-07-08 06:39:11

标签: sprite-kit swift2 skspritenode skcropnode

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

1 个答案:

答案 0 :(得分:1)

如果在用户将手指从屏幕上分离时必须停止球,可能您需要use

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

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

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