I'm working on a spritekit game that uses both ViewControllers and a SpriteKit Scene. Basically, the structure of the application is that you open into a menu (view controller), which through a button press modally segues you to the game (view controller) which loads the GameScene (skscene).
When you lose the game, you are sent to a game over screen (view controller) through a modal segue: gameVC?.performSegueWithIdentifier("goToGameOver", sender: gameVC)
This segue is in the GameScene, and scene.gameVC = self
is in the Game View Controller. gameVC
is initialized in GameScene as var gameVC: UIViewController?
. In the game over screen, you can either go back to the menu or you can play again (go back to game view controller) with button-initialized modal segues.
The problem occurs when you go to the GameScene more than four times. The fifth time that GameScene is opened (either from the menu vc or from the game over vc), the game lags incredibly. The fps counter at the bottom right of the screen says that the game produces 1.5 fps.
I believe the problem is that the GameViewController & the GameScene are not being correctly dismissed (the memory usage of the app increases every time the app moves to GameScene), but I don't know how to correctly dismiss them. I have used
self.removeFromParent()
self.view?.presentScene(nil)
as a way of trying to dismiss the GameScene right before and right after the segue to GameOver code runs, but to no avail. I also thought of unwind segue, but I cannot unwind to a view controller (game over) that I haven't been to yet. I am all out of ideas, and this is a gamebreaking bug. I would really appreciate some help. Thanks very much.
deinit
in your class files and put a print statement in them to make sure they get called – Knight0fDragonself.removeAllChildren()
and `self.removeAllActions()' - does this answer the strong retain cycles? – Comrod33