Time for action – implementing a sound manager
To implement the sound manager, just follow these simple steps:
Add a new Objective-C class called
SoundManager
derived fromAssetsDictionary
within the Assets group.Add an instance method that will register a sound using its filename and return the correct value, as shown in the following code:
-(SPSound *) registerSound:(NSString *)filename;
Implement the method from the previous step with the following content:
-(SPSound *) registerSound:(NSString *)filename { if ([_dict objectForKey:filename] == nil) { return (SPSound *) [self registerAsset:filename withContent:[SPSound soundWithContentsOfFile:filename]]; } else { return (SPSound *) [self registerAsset:filename withContent:nil]; } }
What just happened?
In the first step, we created a SoundManager
class, which is a subclass of AssetsDictionary
. In step 2, we defined the registerSound
method, which we implemented in the next step; this method loads a sound from file and returns...