Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Afterword
Index

Time for action – adding texture atlases to the asset manager


We can extend our asset manager with the following steps:

  1. Open our game's project file, if it's not already open.

  2. Switch to the TextureManager.h file and declare the method registerTextureAtlas, as shown in the following code:

    -(SPTextureAtlas *) registerTextureAtlas:(NSString *) filename;
  3. Switch to the TextureManager.m file and implement the registerTextureAtlas 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];
      }
    }
  4. Head over to the Assets.h file and add the static method textureAtlas:

    +(SPTextureAtlas *) textureAtlas:(NSString*)filename;
  5. In the Assets.m file, implement the following method by referring to its TextureManager...