Page 1 of 1

Flipping in Anim8

Posted: Tue Nov 20, 2012 2:39 am
by Garan
So I was wondering if there is any easy way to have Anim8 flip animations for you. I messaged Kikito, and he told me to post this question here.
My only idea is to have a completely separate image. This is a horrible idea, I would only use it if I had no other choice. I considered seeing if I could use love.graphics to flip the image (I know that is supported) but I realized that the animation would then play backwards.

Re: Flipping in Anim8

Posted: Tue Nov 20, 2012 3:00 am
by verilog
Flipping? You mean flip an image along an axis? For instance, having one image and flipping it while the player is walking to the left/right? I haven't used anim8, but maybe this previous post about flipping images along an axis would be helpful for you: viewtopic.php?f=4&t=9825&p=60239#p60239

good luck! :)

Re: Flipping in Anim8

Posted: Tue Nov 20, 2012 10:32 am
by kikito
verilog is on the right track.

If you look at the animation:draw() function, you will see that it has lots of parameters (most of them optional):

Code: Select all

function Animation:draw(image, x, y, r, sx, sy, ox, oy)
If the parameters sx and sy allow you to flip images, just like in the love.graphics.draw. So you can do this:

Code: Select all

animation:draw(image, x, y, 1, -1, 1) -- flip horizontally
animation:draw(image, x, y, 1, 1, -1) -- flip vertically
animation:draw(image, x, y, 1, -1, -1) -- flip horizontally and vertically
This is now a well-rounded solution. Depending on how your animations are drawn, it might not look right. In particular, some walking animations will look "as if the character was doing the moonwalk" if you simply flip their images.

For those, you will have to create a different animation with the frames in inverted order. Anim8 doesn't have a method to "create an animation with the frames in opposed order", because "opposed order" is a subjective term. But creating it with the grids system should be very simple.

Code: Select all

walkLeft = anim8.newAnimation(g('1-5,1'), 0.1)
walkRight = anim8.newAnimation(g('5-1,1'), 0.1) -- same frames in opposite order
...
walkLeft:draw(image, x, y)
walkRight:draw(image, x, y, 1, -1, 1) -- flipped frames horizontally
Then you can draw the animation with the images flipped, and they should look alright.

EDIT: I've decided to open up an issue in anim8 to investigate this further. Maybe adding one or two methods related with image flipping could benefit everyone. For now, the workaround I'm proposing is the best there is.

Re: Flipping in Anim8

Posted: Tue Nov 20, 2012 8:32 pm
by Garan
I tried the flipping the images, and this may be something that should be examined. When flipping the image, it also flips the draw direction (as in if flipped horizontally, the image is now drawn to the left of the position instead of to the right). Is this supposed to happen, and is there an easy fix?

Re: Flipping in Anim8

Posted: Tue Nov 20, 2012 9:16 pm
by verilog
Are you referring to the offset that is introduced after flipping the image? If so, yeah, that’s normal. Remember that all images are drawn following a coordinate system, the system origin (0,0) is located at the top left of the image, when you flip it horizontally, the origin is still at the top left.

Suppose your image dimensions are 32 x 32, you start drawing your image without any flip, the image will start at screenPosition and will end at screenPosition + 32 for both axes. If you flip the image, it will also start at screenPosition but this time it will end at screenPosition – 32 (for any of the axes).

You can solve this by adding an offset value (same as your image width) when flipping images, check out the original link I posted for more info.

Good luck! :crazy: