Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering iOS Game Development

You're reading from   Mastering iOS Game Development Mastering iOS Game Development

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher Packt
ISBN-13 9781783554355
Length 228 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Peter Ahlgren Peter Ahlgren
Author Profile Icon Peter Ahlgren
Peter Ahlgren
Miguel DeQuadros Miguel DeQuadros
Author Profile Icon Miguel DeQuadros
Miguel DeQuadros
Arrow right icon
View More author details
Toc

Adding awesome sound effects

Yes! We will give our little guy some sound, specifically, when jumping and dying. That's not all though! No no! We will also get some groovy tunes playing in our levels.

Let's open up our GameLevelScene.m file and import the SpriteKit Audio framework to play sounds! At the top of the file where all our import methods are, add the following line:

#import "SKTAudio.h"

I've included some audio for our use as well, so if you haven't imported them into your project, go ahead and do that now, or you can use your own music if you like. Once your file has been imported into the project, back in our GameLevelScene.m file, within our -(id)initWithSize method, we will add the following line of code to get our music playing:

[[SKTAudio sharedInstance] playBackgroundMusic:@"BackgroundAudio.mp3"]; //change the file name to whatever file you imported

Test the project and now you should have some rocking tunes playing in the background!...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime