单击按钮时重新启动iPhone游戏

时间:2014-03-29 14:04:48

标签: objective-c xcode

我对iOS编程足够新,请原谅可能是一个直截了当的问题。

我试图在点击按钮时重启游戏。

有人知道最好的方法吗?

由于

1 个答案:

答案 0 :(得分:1)

重新启动游戏的最简单方法是再次加载场景:

// It's scene you want to restart
// you need to replace YourSKScene with your scene
SKScene *destinationScene = [[YourSKScene alloc] initWithSize:self.size];
// Set up transition type
SKTransition *reveal = [SKTransition fadeWithDuration:0.5];
// Call it from the scene (SKScene subclass)
// Even if the source scene (self) is the same as destination scene it will work
[self.view presentScene: destinationScene transition:reveal];

// EXTENDED

您可以在initWithSize中清除场景的舞台:或者您可以创建方法,例如initWithSize:shouldRestart:方法,将场景清除为场景重新启动时所需的设置,您可以使用上面的解决方案来显示现场。

相关问题