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 – creating an asset container class


To put all of our asset managers into one single class, use the following steps:

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

  2. 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;
  3. In the Asset.m file, import all asset managers, as shown in the following code:

    #import "TextureManager.h"
    #import "SoundManager.h"
    #import "FileManager.h"
  4. 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;
  5. We need to overwrite the internal static initialize method. Use the following piece of code:

    +(void) initialize
    {
        if (!textureAssets) {
           ...