【发布时间】:2015-12-14 02:56:49
【问题描述】:
我正在为我的侄女写一个故事书应用程序,我有一个关于 SpriteKit 的问题。我正在尝试对其进行设置,以便播放不同类型的音频。
- 循环播放的背景音乐 (AVFoundation)
- 在新页面上播放的旁白,或在您按下旁白按钮重播旁白时播放的旁白 (SKAction)
我的问题是,如果用户更改页面,或者如果用户播放重播旁白按钮,旁白将在彼此之上播放。所以它最终听起来像是两个人在互相交谈。
当触发新旁白时,如何停止正在播放的所有旁白?
我在互联网上找不到任何相关帮助。我看过一些帖子说我们是 AVFoundation,但据我了解(尽管有限),这似乎更多地用于背景音乐,并且只能播放一首曲目。
我是否误解了文档?有人可以帮我解答这个问题吗?
import SpriteKit
导入 AVFoundation
class Page1: SKScene {
// MARK: Touch handling
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
println("\(location)")
//checks if someone touched the menu button
if menuButton.containsPoint(location) {
println("Play story with sound!")
settings.setInProgress()
goToPauseMenu()
}
if soundButton.containsPoint(location) {
println("Play story with sound!")
settings.setInProgress()
runAction(playNar)
}
//checks if someone touched the forward button
if pageForward.containsPoint(location) {
println("Next Page!")
settings.setInProgress()
nextPage()
}
}
}
【问题讨论】: