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 – loading our first texture atlas


To load our first texture atlas, we need to follow these steps:

  1. Copy the necessary files (ship_pirate_small_cannon*) into the project.

  2. Load the texture atlas with the following line of code:

    SPTextureAtlas* atlas = [SPTextureAtlas atlasWithContentsOfFile:@"ship_pirate_small_cannon.xml"];
  3. Create an array out of all textures starting with 00:

    NSArray* textures = [atlas texturesStartingWith:@"00"];
  4. Create a movie clip object and position it just above the original pirate ship, as shown in the following code:

    SPMovieClip *cannonShip = [SPMovieClip movieWithFrames:textures fps:20.0f];
    cannonShip.x = 200;
    cannonShip.y = 50;
  5. Play the animation with the following piece of code:

    [cannonShip play];
    [Sparrow.juggler addObject:cannonShip];
  6. Add the animated pirate ship to the display tree as follows:

    [self addChild:background];
    [self addChild:enemyShip];
    [self addChild:_pirateShip];
    [self addChild:cannonShip];
  7. Run the example to see the following result:

What just...