Ok, so I have a sprite kit in Swift, and I'm having trouble reloading GameScene after the game.
Right now, when the user loses his whole life, the gameIsOver variable gameIsOver set to true , which pauses certain nodes within the scene and also turns off the timer. At the end of this timer, I proceed to the scene with the game. From the Game Over scene, the user can either return to their homeland or restart the game.
Here's how I get to my stage game:
countdown(circle, steps: 120, duration: 5) { //Performed when timer ends self.gameSoundTrack.stop() let mainStoryboard = UIStoryboard(name: "Main", bundle: nil) let vc = mainStoryboard.instantiateViewControllerWithIdentifier("GOViewController") self.viewController!.presentViewController(vc, animated: true, completion: nil) //Resetting GameScene self.removeAllChildren() self.removeAllActions() self.scene?.removeFromParent() self.paused = true gameIsOver = false }
I pause my scene because if I donβt, when GameScene restarts, gameIsOver is still set to true and my application crashes. I do not know why this happens if I set gameIsOver to false here.
After moving from GameScene to my game on the stage and back to GameScene or from GameScene to my home view controller and back to GameScene a couple of times, my fps score has decreased so much that the whole game lags behind the point where the gameplay is impossible.
This makes me think that I am not deleting / disposing of GameScene properly every time I present my game on top of the stage.
I believe that I have the same problem as here: In Swift on "game over", move from scene to another UIView and remove the scene? but I am new to this and I cannot understand how they solved their problem.
How can I completely reset / delete GameScene every time I submit my Game Over scene to stop the lag?