TexturePackerの紹介です
公式▶http://www.codeandweb.com/texturepacker
このツール何が凄いのかというと通常画像を一つ一つ
連番で作成するとメモリを食ってしまい処理が遅くなるのですが
一つの画像にまとめて範囲を指定することで画像を取り出すことができ
メモリも節約することができるみたいです。
作り方は簡単で連番画像を用意して
用意した画像を複数選択してアプリ右側のウィンドウへドラッグ
登録されるのでフォーマットをcocos2dに指定してDataFileで
保存場所を指定するだけ。あとはデフォルトでオッケイみたい。
適当なスプライトにアニメーションを適用してやるだけで動きます。
シェアウェアですが下のサイトを参考に登録すると1年間は無料で
使えるみたいです。開発者の方は是非ともつかってみてください。
http://24app.net/blog/archives/3922
//アニメーションさせるスプライトを作成します
CCSprite *sprite = [CCSprite spriteWithFile:@"sample.png"];
sprite.position = ccp(location.x, 50);
[self addChild:sprite z:15];
[[CCSpriteFrameCachesharedSpriteFrameCache] addSpriteFramesWithFile:@"wave.plist"];
NSMutableArray* frames = [NSMutableArrayarrayWithCapacity:15];
for (int i = 0; i <= 15; ++i)
{
NSString* file = [NSString stringWithFormat:@"wave%05d.png", i];
CCSpriteFrame* frame = [[CCSpriteFrameCachesharedSpriteFrameCache]
spriteFrameByName:file];
[frames addObject:frame];
}
//CCAnimationオブジェクト生成
CCAnimation* animation = [CCAnimation animation];
//CCAnimationオブジェクトに複数フレーム(同時にフレームあたりの秒数)を登録します
animation = [CCAnimationanimationWithSpriteFrames:frames delay:0.05];
//アニメーションに無限ループを設定
animation.loops = 1;
//CCAnimateオブジェクトを生成します
CCAnimate* animate = [CCAnimate actionWithAnimation:animation];
CCCallBlock* del = [CCCallBlockactionWithBlock:^{
[self removeChild:sprite cleanup:YES];
}];
CCSequence* seq = [CCSequence actions:animate, del, nil];
//スプライトにCCAnimateオブジェクトを適用します
[sprite runAction:seq];