Join Todd Perkins for an in-depth discussion in this video Play background music, part of iOS Game Development: Swift 2.0 and SpriteKit.
- Playing background music works a little different…from playing a simple sound effect.…To play background music, we're going to use…the SKAudioNode class.…So let's go up to our code at the top.…And then I'm going to create a variable called background.…And this is going to be of the type SKAudioNode.…I'm going to set it as an implicitly unwrapped optional,…and then go down to didMoveToView.…So in here, I'm going to instantiate it.…
Background equals SKAudioNode…and run the constructor with fileNamed…passing in bg.mp3, the name of the file we want to play.…And then to play the file,…you have to actually add it to the screen.…So self.addChild,…and then we pass in background.…So that's the one thing that's different,…maybe not as intuitive as playing a sound effect.…You actually have to use addChild…to start playing the sound.…So now let's just test this to make sure that it's working.…
So I'm going to show the toolbar…and then click to run the application in the simulator.…And we should hear that background music start…
- Creating a new SpriteKit project
- Adding and modifying sprites
- Transitioning between scenes
- Removing child sprites from parents
- Working with gravity, forces, and impulses
- Detecting collisions
- Applying particle effects
- Creating actions and action sequences
- Working with audio
- Creating frame animations
- Using cameras and lights
Skill Level Intermediate
Game Design Careers with Brenda Romerowith Brenda Romero54m 41s Beginner
iOS 9 App Development: GamePlayKitwith Tammy Coron1h 31m Intermediate
1. Introduction to SpriteKit
2. Add Physics
3. Work with Particle Effects
4. Work with Actions
Use an action sequence4m 8s
5. Work with Audio
6. Additional Features
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.