【发布时间】:2015-10-07 18:43:27
【问题描述】:
我需要从 AppDelegate 类中名为 applicationDidEnterBackground 的默认方法调用 GameScene 类中名为 pause() 的方法。
换句话说(在 AppDelegate 中):
func applicationDidEnterBackground(application: UIApplication) {
// Call GameScene method
}
在 GameScene 类中:
func pause() {
// pause game (this method works fine when called elsewhere in the program)
}
我需要在应用进入后台时调用pause()。
GameScene.pause() 不起作用,但我不明白为什么。非常感谢任何帮助。
【问题讨论】:
-
GameScene.pause()不起作用,因为您是在类上调用它,而不是在类的实例上调用它,而且它不是类方法 - 它是实例方法。您需要引用类的实例来调用它。您的GameScene对象在哪里以及如何实例化? -
var scene: GameScene!属于GameViewContoller类。然后在viewDidLoad方法中:scene = GameScene(size: skView.bounds.size)。我希望这能回答你的问题! -
这意味着它在
AppDelegate中不可访问,这是一个不同的类。 -
那么我该如何解决这个问题?
-
等一下,答案来了
标签: ios swift sprite-kit swift2