使用几张图片创建帧动画精灵一

翟俊哲
2023-12-01

auto spriteRun = Sprite::create("man/Run_0.png");

 spriteRun->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));

this->addChild(spriteRun);

Vector<SpriteFrame*> vecSpriteFrame;

for (int i = 0; i < 5; ++i)

{

  char spriteFrameName[20];

  sprintf(spriteFrameName, "man/Run_%d.png", i);

  auto spriteFrame = SpriteFrame::create(spriteFrameName,Rect(0, 0, spriteRun->getContentSize().width, spriteRun->getContentSize().height));

  vecSpriteFrame.pushBack(spriteFrame);

}

 auto animation = Animation::createWithSpriteFrames(vecSpriteFrame,0.2f);

 auto animate = Animate::create(animation);

 spriteRun->runAction(RepeatForever::create(animate));//使用RepeatForever可以让动作重复下去

转载于:https://www.cnblogs.com/xw847455688/p/7992326.html

 类似资料: