【发布时间】:2015-03-12 06:28:56
【问题描述】:
所以我有一个在 SpriteKit 中几乎完全编码的游戏,现在我想在玩家死亡时投放插页式广告。我相信 NSNotifications 将是最好的方法,但我正在努力弄清楚。
所以我有一个设置为显示插页式广告的 UIViewController,它可以工作,但我无法在用户死亡时显示它。
这是来自 ViewController 的一些代码,它具有加载广告的所有功能。我相信这是我使用 addObserver 接收 NSNotification 的地方,但我不确定。
class ViewController: UIViewController, ADInterstitialAdDelegate {
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "showAdSelector", name: "showAnAd", object: nil)
}
func showAdSelector() {
loadAd() //loads the ad
}
然后,这是我在 PlayScene.swift 文件中使用的代码,它是一个 SKScene。
class PlayScene: SKScene, SKPhysicsContactDelegate {
func didBeginContact(contact:SKPhysicsContact) {
loadAnAd()
}
func loadAnAd() {
NSNotificationCenter.defaultCenter().postNotificationName("showAnAd", object: nil)
}
}
当玩家死亡并启动 didBeginContact 函数时,什么也没有发生。我确定我在做一些非常错误的事情,但我一直试图找到答案并观看教程几个小时,但我仍然无法解决它。我将非常感激有人可以帮助我解决这个问题或为我指明正确的方向!谢谢!
【问题讨论】:
标签: swift sprite-kit nsnotificationcenter nsnotifications skscene