         }
     }
     
+    func registerAppTransitionObservers() {
+
+        NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillResignActive", name:UIApplicationWillResignActiveNotification, object: nil)
+        
+        NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationDidEnterBackground", name:UIApplicationDidEnterBackgroundNotification, object: nil)
+
+        NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillEnterForeground", name:UIApplicationWillEnterForegroundNotification, object: nil)
+    }
+    
+    func applicationWillResignActive() {
+        backgroundMusicPlayer.stop()
+        self.scene?.paused = true
+    }
+    
+    func applicationDidEnterBackground() {
+        backgroundMusicPlayer.stop()
+        self.scene?.paused = true
+    }
+    
+    func applicationWillEnterForeground() {
+        self.scene?.paused = false
+        backgroundMusicPlayer.play()
+    }
+    
+    func playBackgroundMusic(filename: String) {
+        let url = NSBundle.mainBundle().URLForResource(
+            filename, withExtension: nil)
+        if (url == nil) {
+            println("Could not find file: \(filename)")
+            return
+        }
+        
+        var error: NSError? = nil
+        backgroundMusicPlayer =
+            AVAudioPlayer(contentsOfURL: url, error: &error)
+        if backgroundMusicPlayer == nil {
+            println("Could not create audio player: \(error!)")
+            return
+        }
+        
+        backgroundMusicPlayer.numberOfLoops = -1
+        backgroundMusicPlayer.prepareToPlay()
+        backgroundMusicPlayer.play()
+    }
+    
     func createPlayButton() {
         playButton.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) + 80)
         playButton.zPosition = 5

        label.fontColor = SKColor.blackColor()
        label.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) + 100 )
        addChild(label)

    }
    

//

import SpriteKit
import AVFoundation

class GameScene: SKScene, SKPhysicsContactDelegate {

