auto s = Director::getInstance()->getWinSize();
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile(“boys/boy.plist”, “boys/boy.png”);
auto sprite = Sprite::createWithSpriteFrameName(“boys/boy_walking_01.png”);
sprite->setPosition(Vec2(s.width * 0.5f, s.height * 0.5f));
//添加子节点,并执行一次绘制有效的节省资源
auto spriteBatch = SpriteBatchNode::create(“boys/boy_walking_01.png”);
spriteBatch->addChild(sprite);
addChild(spriteBatch);
Vector<SpriteFrame*> animFrames(15);
char str = {0};
for(int i = 1; i < 15; i++)
{
// Obtain frames by alias name
sprintf(str, “boy_walking_%0d”, i);
auto frame = cache->getSpriteFrameByName(str);
animFrames.pushBack(frame);
}
auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
// 14 frames * 1sec = 14 seconds
sprite->runAction(RepeatForever::create(Animate::create(animation)));
%url%%url%翻译结果