Time for action – loading our first texture atlas
To load our first texture atlas, we need to follow these steps:
Copy the necessary files (
ship_pirate_small_cannon*
) into the project.Load the texture atlas with the following line of code:
SPTextureAtlas* atlas = [SPTextureAtlas atlasWithContentsOfFile:@"ship_pirate_small_cannon.xml"];
Create an array out of all textures starting with
00
:NSArray* textures = [atlas texturesStartingWith:@"00"];
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;
Play the animation with the following piece of code:
[cannonShip play]; [Sparrow.juggler addObject:cannonShip];
Add the animated pirate ship to the display tree as follows:
[self addChild:background]; [self addChild:enemyShip]; [self addChild:_pirateShip]; [self addChild:cannonShip];
Run the example to see the following result: