So, I read a few questions on this question, but most of them are in Objective-C, and I did not find this address / answer directly. I am new to programming, so please explain all the suggestions in detail.
I need to understand how to free my GameScene after the game is completed. The reason I need to do this is because after the game I switch to the new SKScene (playing backstage), and when I switch back to my GameScene, either GameScene is not reset completely, or I generate a new GameScene every time .
I say this because the frames per second drop every time I get the game and go back to GameScene, so if I do enough, I can no longer play the game. This is problem.
I donβt understand why this is happening, because when I go to my game on stage, I delete everything from my GameScene:
self.viewController!.performSegueWithIdentifier("goToGameOver", sender: nil) self.removeAllChildren() self.removeAllActions() self.scene?.removeFromParent()
I also read here: After closing the SKScene, the memory remains high , that deleting the SKView that contains the SKScene frees up the SKScene, so when both my GameScene and the game over the scenes are left, I delete BOTH views from their supervisors as follows:
override func viewDidDisappear(animated: Bool) { print("its gone") self.view.removeFromSuperview() }
But nothing affects the decrease in the number of frames per second, and the game continues to lag. I donβt understand what Iβm doing, and I canβt say whether playing over the stage is a problem, or Iβm just not releasing GameScene.
How to free up GameScene? What else should I do?
EDIT:
My count and draws counter stays pretty much the same every time I go to GameScene, so that doesn't seem like a problem. I tried to check if deinit was called when switching between scenes (I had no deinit before) using this in the GameScene class:
} //<**End of GAMESCENE** deinit { print("Deinit was called") }
And nothing is printed, so deinit not called.
EDIT 2:
@alex_p This is what I have in my GameViewController-
class GameViewController: UIViewController, SKProductsRequestDelegate, SKPaymentTransactionObserver { var scene1: GameScene? var scene2: GameScene? var skView: SKView?
And I call this method from my GameScene as follows:
self.viewController.nextSceneAction(self)
I copied yours exactly, but I get the error unexpectedly found nil while unwrapping an Optional value in the line commented above. Deinit does not call.