In Swift on “play on top”, move from the scene to another UIView and place the scene?

I have a "life counter" in my game, and when it reaches 0 = dead - I want to move from the scene to another UIView - this is a game with a view - with statistics and a button to return to the screen home (first UIViewController with buttons to launch games, etc.

Here is the code of how I switch to game view

class GameScene: SKScene,SKPhysicsContactDelegate { var viewController: UIViewController? // more code and functions // ...... func trackLife (lifeCHange: Int){ life = life + lifeCHange lifeLabel.text = String(life) if life < 1 { // Go to Game Over VC self.removeAllChildren() self.removeAllActions() self.scene?.removeFromParent() self.viewController!.performSegueWithIdentifier("gameOverSegue", sender: viewController) } } } 

this works to represent the game by viewing, but I think that I do not “order” or transfer the scene. because if I do this in a loop:

Start of the game → Game on top → Back to the main screen → Start of the game → Game on top ...

I see that memory usage is growing on every cycle :) I think I'm just adding scenes but not deleting them?

Sorry - I'm fresh at that. We will be very grateful for your experience! :)

0
source share
1 answer

To effectively manage your memory in the Sprite-Kit , you must create another SKScene for the SKScene screen, which will be presented from your main screen. Thus, the old SKScene will be released.

+2
source

Source: https://habr.com/ru/post/1234442/


All Articles