O'Reilly logo

Learning Swift: Building an iOS Game by Jocelyn Harrigton, Christoffer Hallas, Clayton McIlrath, Paul Nettle, Ankur Patel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Adding sound effects

We now have a fully functional game with scores. It is time to add some sound effects. This is fairly easy to do using Sprite Kit in Swift. Every game has to have background music, so we will see how to add audio and what design patterns we can use to control the audio. We will not only add background music, but we will also look at adding some sound effects for our character when he has acquired a power up or when he dies.

In this chapter we will learn how to add sound to our game using:

  1. AVAudioPlayer
  2. SKAction

AVAudioPlayer is part of the AVFoundation framework, which is used when dealing with audio and video in iOS or Mac OS X. It makes it easy to play audio and provides you with fine tune controlling.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required