【问题标题】:Override function with sprite kit game使用精灵套件游戏覆盖功能
【发布时间】:2016-07-08 06:39:10
【问题描述】:

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

【问题讨论】:

    标签: sprite-kit swift2 skspritenode skcropnode


    【解决方案1】:

    如果你的球必须在用户将手指从屏幕上移开时停止,可能你想use

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

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      • 1970-01-01
      • 1970-01-01
      • 2017-03-12
      • 1970-01-01
      相关资源
      最近更新 更多