Book Image

Learning iOS 8 Game Development Using Swift

By : Siddharth Shekar
Book Image

Learning iOS 8 Game Development Using Swift

By: Siddharth Shekar

Overview of this book

<p>Game development has been simplified with Apple's new programming language—Swift. If you're looking to start learning iOS development then you'll get everything you need - from&nbsp;the absolute basics such as the Xcode interface and takes you all the way to Swift programming.</p> <p>You will take a walk through the creation of 2D and 3D games followed by an introduction to SpriteKit and SceneKit. The book also looks at how game objects are placed in 3D scenes, how to use the graphics pipeline, and how objects are displayed on mobile screens. You will also delve into essential game concepts such as collision detection, animation, particle systems, and scene transitions. Finally, you will learn how to publish and distribute games to the iTunes store.</p>
Table of Contents (18 chapters)
Learning iOS 8 Game Development Using Swift
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Adding background music


Our game is now populated with sound effects, but it will be so much more awesome if we add background music. Since the player will need to keep switching between MainMenuSceen and GameplayScene, there is no point in using SKAction to play sounds, as it won't play correctly or will get truncated each time the scene is changed.

For this purpose, we will have to use Apple's audio visual class called AVFoundation to help us get around this issue. As you might have guessed, AVFoundation is a superclass that handles both the audio and video functionalities, so if you want any video to be played in your game (say, for a tutorial), then you can very well use this class—that is why it was created. But let's get back to including the background music in our game.

Adding audio loops

To create audio loops, we have to import AVFoundation, and since we have to play the audio track as soon as the game starts, let's add it in the GameViewController class. So, add the following at the...