Reputation: 133
I'm writing a small 2d game with Swift and Spritekit. I have a gameOver() function which makes the view go to another scene (end the game), it works fine in the touchesBegan() function, but in the update() function when the conditions are met it just freezes the game, didn't go to the new scene, what's the problem ? My guess is that the update() function only has 1 frame of time to finish the job, and it can't finish the gameOver() function in that short amount of time, is it ?
Here's the code:
override func update(currentTime: CFTimeInterval) {
if hero.position.y <= 0 {
gameOver()
}}
Upvotes: 0
Views: 364
Reputation: 11696
Your update method is probably calling the gameOver method repeatedly. You need to add a BOOL and set it to true on the first call, to only have it called once.
Upvotes: 1