I have some sprites, where the player character is facing to the right. I can create an animation from those sprites just fine. The problem is, if I want the sprites to face to the left.
I do the following:
Sprite* p = Sprite::createWithSpriteFrameName("Jumping");
p->setPosition(Vec2(_visibleSize.width/2,_visibleSize.height/2));
this->addChild(p);
p->setFlippedX(true);
Vector<AnimationFrame*> animFrames;
float frameRate = 0.32f;
std::vector<std::string> frameNames = {"Running 0","Running 1","Running 2"};
for (int i =0; i<3;i++){
auto frameName = frameNames.at(i);
auto spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frameName);
ValueMap userInfo;
userInfo["frame_index"] = Value(i);
auto animFrame = AnimationFrame::create(spriteFrame, frameRate, userInfo);
animFrames.pushBack(animFrame);
}
auto animation = Animation::create(animFrames, frameRate);
auto animationAction = Animate::create(animation);
p->runAction(RepeatForever::create(animationAction));
p->setFlippedX(true);
The animation runs, but the animation still shows the player facing to the right. What is the problem? Why doesn't setFlippedX
work in this case?
I am using Cocos2d-x 3.13.1. I can't find any bug, so I assume I am doing something incorrectly.