AppleTattooGuy
AppleTattooGuy

Reputation: 1175

Using motion in SpriteKit

Swift noob here so please bear with me!

I have been following tutorials to implement motion into my SpriteKit (Swift 3) game. I have the following code:

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)
                }

            })

        }

    }
}

I am getting errors on the startAccelerometerUpdates line in relation to the operation queue:

'Call value of non-function type OperationQueue'

I have tried a few ways to do this and have been searching around for it, am I missing the obvious?

Upvotes: 3

Views: 140

Answers (1)

OldManMcDonalds
OldManMcDonalds

Reputation: 1167

Try

OperationQueue.current

instead of

OperationQueue.currentQueue()

Apple did a bunch of these changes for Swift 3.

Upvotes: 3

Related Questions