LoginSignup
3
3

More than 5 years have passed since last update.

cocos2d-xとZwoptexによるアニメーション

Posted at

Zwoptex

スクリーンショット 2014-05-10 11.10.34.png

画像を集めたテクスチャアトラスと座標情報等をまとめたプロパティリストを作ってくれるツール。
ぱたぱたアニメ(口を閉じてる画像と開けてる画像の切り替えで会話をしている動き)を実現したくて使用。

複数の画像をドラッグ&ドロップ→Layoutボタンクリックで自動整列→Publishボタンクリックでテクスチャアトラス(png)とプロパティリスト(plist)が生成される。生成先はPublish Settingsで設定できる。

cocos2d-x

  • addSpriteFramesWithFileでplistを設定する。
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("characters.plist");
  • createWithSpriteFrameNameで画像を参照できる。
  • SpriteFrame*のVectorとAnimationでアニメーションできる。
auto frames = new Vector<SpriteFrame *>();
frames->pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("MouseOpen.png"));
frames->pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("MouseClose.png"));
Animation *animation = Animation::createWithSpriteFrames(*frames, 0.3f);
animation->setLoops(-1);    // forever
sprite_man_center->runAction(RepeatForever::create(Animate::create(animation)));
delete frames;

いいと思ったこと

  • テクスチャアトラスを読み込んでおけば、中の画像をテクスチャアトラスを作った時の画像ファイル名で参照できる
  • テクスチャアトラスの画像はツールが自動で並べてくれる。画像ファイル名でアクセスするから、画像の並びは気にしなくてよい→画像ファイルに命名規則があると後々よい。
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3