代码如下:
auto vSize = Director::getInstance()->getVisibleSize();
auto hand = Sprite::createWithSpriteFrameName("hand_0001.png");
//使用这个方法创建说明图片是在plist文件下,并且被加载
hand->setPosition(vSize / 2);
this->addChild(hand);
auto animation = Animation::create();
SpriteFrame * frame = SpriteFrameCache::getInstance()->getSpriteFrameByName("hand_0001.png");
SpriteFrame * frame_1 = SpriteFrameCache::getInstance()->getSpriteFrameByName("hand_0002.png");
animation->addSpriteFrame(frame);
animation->addSpriteFrame(frame_1);
animation->setDelayPerUnit(0.3f);//设置播放的时间间隔
animation->setLoops(-1);//设置循环次数 -1永久循环
auto action = Animate::create(animation);
hand->runAction(action);
如果说使用的图片很多, hand_0001.png 一直到 hand_0100.png 这种情况
可以参照这篇文章进行字符串拼接
for(int i = 1; i != 101; ++i)
{
std::string str = StringUtils::format("hand_%d.png", i);
SpriteFrame * frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(str);
animationReveal->addSpriteFrame(frame);
}