I need to flip a card to see its back, then side and then front gradually with animation. How I can do this with cocos2d-x? I have took a look on OrbitCamera and RotateBy in 3D tests. They are very close to the one I want to, the only problem is that when the sprite turns around I see not the back (as it should be another texture), but the same spite from back camera. I understand that I should use 2 sprites to get the effect, but how I should do that, I don’t know. Should I position 2 sprite with different Z order?
I am pretty sure that I should replace the texture of the sprite but the problem is that when I rotate with OrbitCamera by 90 degree and replace the texture with back image of the card, then it does remain 90 degree rotated. Instead it turnes so that the whole texture was visible. But it had to be 90 degree turned and see from the side as one line.
@slackmoehrle you are right visibility can help, but in the article above you can see the explanation why OrbitCamera is not a good solution if the card in not in the center of the screen.
I tried to flip a box but I had a trouble, so I changed RotateBy to FadeIn/Out actions
It is code from my project, so something can be confusing. Main idea is Sequence of Actions.
void Square::invertWithAnimation()
{
if (_start_inverting || this->getNumberOfRunningActions())
{
this->stopAllActions();
if (_start_inverting)
{
_start_inverting = false;
_inverted = !_inverted;
}
if (_inverted)
this->initWithFile(BOX_INVERTED);
else
this->initWithFile(BOX_NON_INVERTED);
}
auto anim = FadeOut::create(0.2);
_start_inverting = true;
auto finish_act = CallFunc::create([&]()
{
_inverted = !_inverted;
_start_inverting = false;
if (_inverted)
this->initWithFile(BOX_INVERTED);
else
this->initWithFile(BOX_NON_INVERTED);
auto anim = FadeIn::create(0.2);
runAction(Sequence::create(anim, nullptr));
});
runAction(Sequence::create(anim, finish_act, nullptr));
}
I double check the issue you mentioned in my latest published game (Cocos2d-x 3.2 final) and you are right. There is issue if you use OrbitCamera and set the rotation as 90 degree.
But as far as we only care the front/back side of the card, OrbitCamera works nice.
What you need is to display correct sprite by checking eye vector in overrided Update function.
@winipcfg what you mean by saying “you need is to display correct sprite by checking eye vector in overrided Update function”. Maybe you code write a code for us?