Jack Schofield
Jack Schofield

Reputation: 302

In objective C, when presenting a new scene, how do you remove the old scene?

I am new to Objective-C, so I may be using the wrong methodology to present the scene in the first place, but at the moment when I present my new scene, the old scene can be seen through it.

- (void)buttonClicked:(UIButton*)button
{
    NSLog(@"Button %ld clicked.", (long int)[button tag]);
    WarScene *battle = [[WarScene alloc] initWithSize: CGSizeMake(1024,768)];
    SKTransition *reveal = [SKTransition       revealWithDirection:SKTransitionDirectionDown duration:1.0];
    SKView * skView = (SKView *)self.view;
    [skView presentScene:battle transition:reveal];
}

Is there something that I first have to write before the presentScene method which removes the current scene?

Sorry if this is a very basic question, I have already googled around and looked for examples, but none seem to have any additional code which I'm missing which suggests that I am probably presenting the scene wrong in the first place.

Upvotes: 3

Views: 516

Answers (2)

MaxKargin
MaxKargin

Reputation: 1545

Good News! You don't have to write anything to remove the old scene. It is removed automatically since Sprite Kit does all of the deallocating for you. However, if you need you can do extra "wrap up" in the didMoveFromView method.

Now, people in the past have reported what you are going through. My advice is instead of transitioning between SKScenes, transition between SKViews that present their own SKScene. This way you will ensure that EVERYTHING is automatically deallocated by keeping it all seperated. See this answer, I think it will help you a lot.

Best of luck!

Upvotes: 4

Munahil
Munahil

Reputation: 2419

You don't need to write any code to remove the old scene. Sprite Kit will do it itself. However if you want to do so, you can do following :

  [skView presentScene:nil];

Also this stackoverflow's question may further clarify you.

Upvotes: 0

Related Questions