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

余生颓废 提交于 2020-01-24 10:13:20

问题


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.


回答1:


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!




回答2:


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.



来源:https://stackoverflow.com/questions/31924658/in-objective-c-when-presenting-a-new-scene-how-do-you-remove-the-old-scene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!