1
votes

I am a beginner programmer developing a game in Xcode's sprite-kit. I want to make a game-over scene using a different SKScene. I know that using the view-controller, if you transition to a second view-controller (say from the game view to the game-over view), when we want to go back to a previous view-controller we would use the following line of code:

        [self.navigationController popViewControllerAnimated:YES];

Is there an equivalent to this for SKScene? The method I am using seems to create a new instance of the game SKScene (so the memory increases a lot each time I go between scenes).

Specifically I'm using the following (1) to go from game scene to the game-over scene and (2) to go from game-over scene to the game scene:

(1) (this is GamePlayScene.m)

SKScene *gameOverScene = [[LTGameOverScene alloc] initWithSize:self.size loss:YES];
SKTransition *reveal = [SKTransition fadeWithDuration:0.5];
[self.view presentScene:gameOverScene transition:reveal];

(2) (these is GameOverScene.h)

-(id)initWithSize:(CGSize)size loss:(BOOL)loss 
...
    SKTransition *reveal = [SKTransition flipHorizontalWithDuration:0.5];
    MyScene * scene = [MyScene sceneWithSize:self.view.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;
    [self.view presentScene:scene transition: reveal];
1
It is up to you to manage the scenes in your game; there is no built-in behavior like storyboards for traditional apps. You will need to create your own push/pop scene controller or you can simply transition to new scenes and have the old scene (and its contents) automatically released.0x141E

1 Answers

0
votes

Because when you present another SKScene (GameOverScene), the previous SKScene (MyScene) deallocates itself after transition.