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!...