【问题标题】:Using motion in SpriteKit在 SpriteKit 中使用动作
【发布时间】:2016-11-28 21:12:51
【问题描述】:

这里是 Swift 菜鸟,所以请多多包涵!

我一直在按照教程在我的 SpriteKit (Swift 3) 游戏中实现运动。我有以下代码:

class GameScene: SKScene {


    let player = SKSpriteNode(imageNamed: "Airplane")

    override func didMove(to view: SKView) {

        backgroundColor = SKColor.white

        player.position = CGPoint(x: size.width * 0.1, y: size.height * 0.5)

        addChild(player)

        if motionManager.isAccelerometerAvailable == true {

                motionManager.startAccelerometerUpdates(to: OperationQueue.currentQueue(), withHandler:{

                data, error in

                var currentX = self.player.position.x

                // 3
                if data.acceleration.x < 0 {
                    self.destX = currentX + CGFloat(data.acceleration.x * 100)
                }

                else if data.acceleration.x > 0 {
                    self.destX = currentX + CGFloat(data.acceleration.x * 100)
                }

            })

        }

    }
}

我在与操作队列相关的 startAccelerometerUpdates 行上遇到错误:

'Call value of non-function type OperationQueue'

我已经尝试了几种方法来做到这一点并且一直在寻找它,我是否错过了明显的?

【问题讨论】:

    标签: swift sprite-kit swift3


    【解决方案1】:

    试试

    OperationQueue.current
    

    而不是

    OperationQueue.currentQueue()
    

    Apple 为 Swift 3 做了很多这些更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      相关资源
      最近更新 更多