Playing Sound Effects in the Scene

When you’re ready to implement one-shot sound effects in your game, there’s no need to reach for the iOS audio APIs. Sprite Kit gives us everything we need with a special sound action. Let’s add some shooting and explosion effects for the collisions.

First, we need to make sure the sound files are in the Xcode project. If you’re creating the project yourself on the fly, drag the obstacleExplode.m4a, shipExplode.m4a, and shoot.m4a files into the Xcode file sidebar. Make sure the SpaceRun target checkbox is checked, like in Figure 7, Dragging and dropping files into the Xcode project. Xcode doesn’t always check that box for you for some file types.

Next, we need three properties on our scene object to hold ...

Get Build iOS Games with Sprite Kit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.