Time for action – creating an asset container class
To put all of our asset managers into one single class, use the following steps:
Add a new Objective-C class called
Assets
derived fromNSObject
within the Assets group.Define a static method for each kind of asset, as shown in the following code:
+(SPTexture *) texture:(NSString *)filename; +(SPSound *) sound:(NSString *)filename; +(NSString *) plainText:(NSString *)filename; +(NSDictionary *) dictionaryFromJSON:(NSString *)filename;
In the
Asset.m
file, import all asset managers, as shown in the following code:#import "TextureManager.h" #import "SoundManager.h" #import "FileManager.h"
For each manager, add a static variable with the appropriate type and set its values to
nil
:static TextureManager *textureAssets = nil; static SoundManager *soundAssets = nil; static FileManager *fileAssets = nil;
We need to overwrite the internal static
initialize
method. Use the following piece of code:+(void) initialize { if (!textureAssets) { ...