【发布时间】:2015-12-13 10:26:03
【问题描述】:
升级到 XCode 7.2 后,我遇到一个问题,即 SKAudioNode 只播放了一秒钟,然后停止播放。我没有更改代码中的任何内容。
在我的 GameViewController 中,我将 MenuScene 称为:
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let scene = MenuScene(size: view.bounds.size)
let skView = view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
scene.scaleMode = .ResizeFill
skView.presentScene(scene)
}...
在我的 MenuScene 中,我这样称呼我的 GameScene:
func launchScene() {
let gameView = view! as SKView
let gameScene = GameScene(size: self.size)
gameView.ignoresSiblingOrder = true
let reveal = SKTransition.fadeWithDuration(0.5)
gameView.presentScene(gameScene, transition:reveal)
}
然后在我的 GameScene 中添加一个 SKAudioNode:
class GameScene: SKScene, SKPhysicsContactDelegate {
override func didMoveToView(view: SKView) {
...
let backgroundMusic = SKAudioNode(fileNamed: "main.mp3")
backgroundMusic.autoplayLooped = true
addChild(backgroundMusic)
...
}
}
所以,问题是当我点击一个调用 launchScene() 函数的按钮时,背景音乐开始播放,但大约 1 秒后停止播放。
编辑:似乎背景音乐之前开始播放!到另一个场景的过渡开始了,当另一个场景(gameScene)“终于到了”(不知道如何描述它)时,音乐停止播放。我不知道为什么,因为我在“didMoveToView”函数的gameScene中添加了backgroundMusic。
我在这里做错了什么,因为它在 XCode 7.1 中完美运行?
【问题讨论】:
-
只是一个疯狂的猜测,
backgroundMusic.positional有没有可能搞砸了?你确定backgroundMusic不会很快打电话给removefromparentnode吗? -
我评论了 .removeFromParentNode ,它就像描述的那样发生了。 .positional 也没有帮助。好像背景音乐之前开始播放了!到另一个场景的过渡开始了,当另一个场景(gameScene)“终于到了”(不知道如何描述它)时,音乐停止播放。我不知道为什么,因为我在“didMoveToView”函数的gameScene中添加了backgroundMusic。
-
奇怪的事情,如果我将时间从 SKTransition.fadeWithDuration(0.5) 减少到 (0) 它可以工作。这是怎么回事?
标签: ios xcode swift sprite-kit tvos