Raz
Raz

Reputation: 9058

Libgdx rotate an actor on its Y axis

I'm trying to do a card flip animation in Libgdx. Sprites and Actors support only rotation clockwise/counter-clockwise. So I thought that I can achieve that by using the Rotate function in the camera object. The problem is that it affects the whole stage and not just the actor.

How can I achieve this affect without creating a new stage?

Upvotes: 1

Views: 1853

Answers (1)

florianbaethge
florianbaethge

Reputation: 2560

Well you have never defined what the back side of a card looks like, since actors are just images ;)

What you could do is to use two images, one for the front, one for the back (which is at first invisible).

When flipping the card you would add an Action that scales the x-component of the frontImage to 0, and then scales the backimage from 0 to 1.

So at first you would have to hide the backimage

cardBack.addAction(Actions.scaleTo(0,1);

Then when flipping, you could do something like this:

cardFront.addAction(Actions.scaleTo(0,1, DURATION/2));
cardBack.addAction(Actions.delay(DURATION/2), Actions.scaleTo(1,1, DURATION/2));

Hope this helps... :)

Upvotes: 2

Related Questions