Game Development Reference
In-Depth Information
When you're done with the Output settings, simply click Publish, and TexturePacker
will write the HD and SD textures and the accompanying plist files to your Re-
sources folder.
Using the Texture Atlas with cocos2d
The next thing you should do is add the new texture atlas to the Xcode project's Re-
source group. Cocos2d only needs the game-art-hd.pvr.ccz , game-
art.pvr.ccz , game-art-hd.plist , and game-art.plist files for the tex-
ture atlas. Don't add the TexturePacker .tps files and individual source image files to
your project. The code in Listing 6-13 now replaces the code in Listing 6-11 .
Listing 6-13. The Ship Class Now Uses the Texture Atlas for Its Initial Frame and the
Animation
// Load the texture atlas sprite frames; this also loads the Texture with the same name
CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"game-art.plist"];
// Loading the ship's sprite using a sprite frame name (e.g., the file name)
if ((self = [super initWithSpriteFrameName:@"ship.png"]))
{
// Load the ship's animation frames
NSMutableArray* frames = [NSMutableArray arrayWithCapacity:5];
for (int i = 0; i < 5; i++)
{
NSString* file = [NSString stringWithFormat:@"ship-anim%i.png", i];
CCSpriteFrame* frame = [frameCache spriteFrameByName:file];
[frames addObject:frame];
}
// Create an animation object from all the sprite animation frames
CCAnimation* anim = [CCAnimation animationWithSpriteFrames:frames delay:0.08f];
// Run the animation by using the CCAnimate action
CCAnimate* animate = [CCAnimate actionWithAnimation:anim];
 
 
Search Nedrilad ::




Custom Search