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 – managing our textures


To create our texture manager, take a look at the following steps:

  1. Add a new Objective-C class called TextureManager derived from AssetsDictionary within the Assets group.

  2. 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;
  3. 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];
      }
    }
  4. Switch to the Game.m file, and replace the AssetsDictionary.h import with the TextureManager.h file in the import section.

  5. In the init method, replace the AssetsDictionary test we did earlier in the chapter with the following lines:

    TextureManager...