テクスチャアトラスを簡単に作れるツール Zwoptex を使ってみます。
ツール自体は簡単!
ドラッグアンドドロップでファイルを追加し、Publishボタンを押すだけです。
出力されるファイルは2つあります。
- plistファイル
- pngファイル
黒と白の画像を交互に入れ替えるアニメーションのサンプルです。
サンプル
// 最初にplistファイルを読み込む.
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("test-0001-default.plist");
// Spriteを表示する.
auto sprite = Sprite::createWithSpriteFrameName("black.png");
sprite->setPosition(100, 100);
this->addChild(sprite);
// アニメーションさせる.
Vector<SpriteFrame *> frames;
frames.pushBack(cache->getSpriteFrameByName("black.png"));
frames.pushBack(cache->getSpriteFrameByName("white.png"));
Animation *animation = Animation::createWithSpriteFrames(frames, 0.5f);
Animate *animate = Animate::create(animation);
RepeatForever *repeat = RepeatForever::create(animate);
sprite->runAction(repeat);
簡単ですね。
以上