【发布时间】:2016-08-13 06:52:25
【问题描述】:
我目前正在开发一个小游戏,气球从屏幕底部浮起来,玩家必须在它们到达顶部之前将它们弹出。
每个气球对象都包含一个安全设置它的 AVAudioPlayer 的方法:
func setUpAudioPlayerWithFile(file:NSString, type:NSString) -> AVAudioPlayer? {
let path = NSBundle.mainBundle().pathForResource(file as String, ofType: type as String)
let url = NSURL.fileURLWithPath(path!)
var audioPlayer:AVAudioPlayer?
do {
try audioPlayer = AVAudioPlayer(contentsOfURL: url)
}catch {
print("BALLOON ERROR - AudioPlayer not avaliable.")
}
return audioPlayer
}
然后在每个气球的 init() 方法中运行以下代码:
if let popSound = self.setUpAudioPlayerWithFile("PopSound", type: "wav") {
self.popSound = popSound
}
在游戏开始几分钟之前,这绝对可以正常工作。此时我开始收到“BALLOON ERROR - AudioPlayer not available”。在控制台中,从那时起产生的每个气球都表明我的资源没有被发现?
此时我的 SKEmitterNodes 也开始返回 nil。 (2016-08-13 18:59:54.527 Stop & Pop[256:13785] *** -[NSKeyedUnarchiver initForReadingWithData:]: 数据为 NULL)
有什么明显的我遗漏的东西可能导致这些错误吗?
希望我已经提供了足够的信息,感谢您的阅读。
【问题讨论】:
标签: ios swift avaudioplayer skemitternode