Question

I'm writing an arcade multi-level game with Slick2D and I'm writing the code of the entities. I'm trying to flip horizontally the sprite. The first time I designed 2 images for the same sprite, the first facing right and the second facing left.

Now I'm trying to flip horizontally the sprite with the getFlippedCopy() function, but I cannot rotate the entire animation, I can rotate only a frame.

How can I solve?

Was it helpful?

Solution

If you are drawing an animation, it can be best to utilize the getCurrentFrame() method, as that's what's about to be displayed anyway.

Do something like this:

animation.getCurrentFrame().getFlippedCopy(direction, false).draw(x, y);

With this in your render method, you set the orientation of the image based on the direction they are face. So if they are facing left, 'direction' could be true, so the current animation image will draw flipped at that x and y (which is what you want), and if facing right, direction would be false, in which no flipped orientation would occur and it would show the player facing right (depending on the image; if they are facing left in the original spritesheet, the opposite will be true).

If you are doing a bit more complex orientation changes, such as 4 directional movement:

anim.getCurrentFrame().setRotation(90*(direction));
anim.getCurrentFrame().draw(x, y);

where 'direction' is a North/East/South/West representative integer, 0-3. Such as 0 = North, 1 = East, etc etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top