Time for action – adding texture atlases to the asset manager
We can extend our asset manager with the following steps:
- Open our game's project file, if it's not already open.
- Switch to the
TextureManager.h
file and declare the methodregisterTextureAtlas
, as shown in the following code:-(SPTextureAtlas *) registerTextureAtlas:(NSString *) filename;
- Switch to the
TextureManager.m
file and implement theregisterTextureAtlas
method, as shown in the following code:-(SPTextureAtlas *) registerTextureAtlas:(NSString *) filename { if ([_dict objectForKey:filename] == nil) { return (SPTextureAtlas *) [self registerAsset:filename withContent:[SPTextureAtlas atlasWithContentsOfFile:filename]]; } else { return (SPTextureAtlas *) [self registerAsset:filename withContent:nil]; } }
- Head over to the
Assets.h
file and add the static methodtextureAtlas
:+(SPTextureAtlas *) textureAtlas:(NSString*)filename;
- In the
Assets.m
file, implement the following method by referring to...