1
votes

I'm creating a game with spriteKit. I have made a SKSpriteNode that when tapped jumps. To calculate a score I would like to use an updated variable that I can use in didMove.

I've tried using the a override func update (outside didMove) to update the height before every frame, but I'm not able use in didMove.

This is what I tried:

override func update(_ currentTime: CFTimeInterval) {
   let ballPosition:Int = Int((ball?.position.y)!)

}

Thanks in advance.

1

1 Answers

0
votes

I'm not entirely sure if I understood the question correctly, but you want to place this inside the method just below the code that makes your node jump:

(Make sure to create a variable for your score inside or outside your class. For my example I use let score)

// Update score
score = Int(ball.position.y)

In this way every time your ball jumps (ex. on a tap) your score is updated with a integer value equal to the balls y-position.

Another way of achieving a score could be to set a static score-value for each tap.

For instance:

// Update score
score = score + 1

I hope this helps. If so, please mark it as an answer :-)

Best of luck with your game! :-)