SKScene Fails to deallocate memory resulting in bounded memory growth

后端 未结 3 1125
暖寄归人
暖寄归人 2021-01-06 01:05

I have been struggling with this for days, for some reason my SKScenes are not deallocating correctly, this results in bounded memory growth as each time i exit and enter a

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 01:25

    In a game I'm working on I have a method for going on to the next scene. It looks like this:

    func proceedToNextLevel() {
        // Go to next level
        self.physicsWorld.removeAllJoints()
        self.enumerateChildNodesWithName("cube", usingBlock: {
            (node: SKNode!, stop: UnsafeMutablePointer ) -> Void in
            // do something with node or stop
            node.removeFromParent()
        })
        player.removeFromParent()
        hud.removeFromParent()
    }
    

    Each level is a scene that inherits this method. (I have a GameScene.swift, and every level is a subclass of it)

    This method in each level looks like this:

    override func proceedToNextLevel() {
        super.proceedToNextLevel()
        let transition = SKTransition.revealWithDirection(SKTransitionDirection.Right, duration: 3)
        let newScene: LevelFourScene = LevelFourScene.unarchiveFromFile("LevelFourScene") as! LevelFourScene
        newScene.scaleMode = SKSceneScaleMode.AspectFit
        self.view?.presentScene(newScene)
    }
    

    Obviously this is swift and your game is in Objective C but hopefully you get the idea.

提交回复
热议问题