SpriteFrame 需要创建一帧帧的精灵,然后通过Animation进行合并成一个动画,Animate是一个action,用来加载动画,然后进行播放
anim_array = Array::create();
anim_array->retain();
Vector<SpriteFrame* > frameArray;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
auto sprite = SpriteFrame::create("fenghuang.png", Rect(j*BIRD_WIDTH, i*BIRD_HIGHT, BIRD_WIDTH, BIRD_HIGHT));
frameArray.pushBack(sprite);
}
auto animation = Animation::createWithSpriteFrames(frameArray, 0.1f);
anim_array->addObject(animation);
frameArray.clear();
}
auto animation = static_cast<Animation*>(anim_array->getObjectAtIndex(0));
auto spritebird = Sprite::create("fenghuang.png", Rect(0, 0, BIRD_WIDTH, BIRD_HIGHT));
spritebird->setName("bird");
this->addChild(spritebird);
auto aciton = Animate::create(animation);
spritebird->setPosition(Point(200, 200));
spritebird->runAction(RepeatForever::create(aciton));