Flipping in Anim8

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Garan
Prole
Posts: 17
Joined: Tue May 01, 2012 2:37 am

Flipping in Anim8

Post 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.
User avatar
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Re: Flipping in Anim8

Post 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! :)
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Flipping in Anim8

Post 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.
When I write def I mean function.
User avatar
Garan
Prole
Posts: 17
Joined: Tue May 01, 2012 2:37 am

Re: Flipping in Anim8

Post 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?
User avatar
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Re: Flipping in Anim8

Post 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:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 44 guests