Time for action – managing our textures
To create our texture manager, take a look at the following steps:
Add a new Objective-C class called
TextureManager
derived fromAssetsDictionary
within the Assets group.Add an instance method that will register a texture using its filename and return the correct value, which is the following:
-(SPTexture *) registerTexture:(NSString *)filename;
Switch to
TextureManager.m
and implement the method with the following content:-(SPTexture *) registerTexture:(NSString *)filename { if ([_dict objectForKey:filename] == nil) { return (SPTexture *) [self registerAsset:filename withContent:[SPTexture textureWithContentsOfFile:filename]]; } else { return (SPTexture *) [self registerAsset:filename withContent:nil]; } }
Switch to the
Game.m
file, and replace theAssetsDictionary.h
import with theTextureManager.h
file in theimport
section.In the
init
method, replace theAssetsDictionary
test we did earlier in the chapter with the following lines:TextureManager...