Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


David Bauer
David Bauer
3,863 Points

After upgrading to XCode7.2 SKAudioNode won't play

I have a problem after upgrading to XCode 7.2 that a SKAudioNode just plays like one second and then stops playing. I changed nothing in the code.

In my GameViewController I call the MenuScene like:

class GameViewController: UIViewController {
    override func 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

And in my MenuScene I call my GameScene like this:

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)

And then in my GameScene I add a SKAudioNode:

class GameScene: SKScene, SKPhysicsContactDelegate {
    override func didMoveToView(view: SKView) {
    let backgroundMusic = SKAudioNode(fileNamed: "main.mp3")
    backgroundMusic.autoplayLooped = true

So, the problem is that when I hit a Button that calls the launchScene() function the background Music starts playing but stops playing after approximately 1 second.

It seems that the backgroundMusic starts playing before! the transition to the other scene begins and when the other scene (gameScene) is "finally there" (dunno how to describe it) the music stops playing. I don't know why since I add the backgroundMusic in the gameScene in the "didMoveToView" function. Another weird thing is when I reduce the SKTransition.fadeWithDuation to (0) it works. And I don't know why.

What am I doing wrong here since it works flawlessly in XCode 7.1?