Search code examples
c++animationcocos2d-xspritecocos2d-x-3.0

C++ - How to play animation in opposite direction Cocos2DX


I got a png like this

enter image description here

I also got this segment of code

SpriteFrameCache::getInstance()->addSpriteFramesWithFile("walk.plist", "walk.png");
Vector<SpriteFrame*> animFrames;
animFrames.reserve(8);
char spriteFrameByName[MAX_WORD] = { 0 };

for (int index = 1; index <= 8; index++)
{

    sprintf(spriteFrameByName, "%d.png", index);

    auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameByName);

    animFrames.pushBack(frame);
}
Animation* animation = Animation::createWithSpriteFrames(animFrames, time);
sprite->runAction(Animate::create(animation));

Now I want to horizontally flip this animation. Something looks like this

enter image description here

Not to create another png file, is there a way to this in C++ code?


Solution

  • Animation* animation = Animation::createWithSpriteFrames(animFrames, time);

    sprite->runAction(Animate::create(animation));

    sprite->setFlipX(true)