SpriteKit presentScene () Memory leak
I have a game with a Menu Scene and a Game Scene . In the Menu Scene, I start the game with:
let transition = SKTransition.fadeWithDuration(1)
let scene = GameScene(size: self.scene!.size)
scene.scaleMode = self.scaleMode
self.view!.presentScene(scene, transition: transition)
When the game is over, I use the following code in the Game Scene to return to the Scene menu :
let transition = SKTransition.fadeWithDuration(1)
let scene = MenuScene(size: self.scene!.size)
scene.scaleMode = self.scaleMode
self.view!.presentScene(scene, transition: transition)
So far so simple. But with each hop, memory consumption increases. Is there a way to avoid this? For example, reuse the menu scene?
This is how I load the first MenuScene into the GameViewController:
override func viewWillLayoutSubviews() {
let skView = self.view as! SKView
skView.showsFPS = true
skView.ignoresSiblingOrder = true
var scene = MenuScene(size: skView.bounds.size)
scene.scaleMode = SKSceneScaleMode.AspectFill
skView.presentScene(scene)
}
+3
source to share
No one has answered this question yet
Check out similar questions: