Page 1 of 2

Anim8: Vote your preferred flip method syntax

Posted: Sun Dec 02, 2012 9:50 pm
by kikito
Hi there,

Some days ago someone mentioned his desire to have a way to "flip" animations in anim8. So, for example, if you have a walking animation of someone moving to the left, you could generate the walking to the right animation from it with a single command, reusing the image.

I like this, because it would make code smaller and also save some memory.

What I need is to find a good API to do that.

So far I've come up with the following alternatives:

Code: Select all

    local a = anim8.newAnimation(...)

    local a1 = anim8.flipH(a) -- vertical: anim8.flipV(a)
    local a2 = anim8.flip('h', a) -- vertical: anim8.flip('v', a)
    local a3 = a:flip('h') -- or a:flip('v')
    local a4 = a:flipH() -- or a:flipV() 
I've got a favourite one, but I'd like to hear what you think. Please vote the syntax you'd rather have.

Re: Anim8: Vote your preferred flip method syntax

Posted: Sun Dec 02, 2012 10:44 pm
by Santos
Hmmmmmmmm...

Methods seem nice, and a4 is cool because it doesn't use constants and you can also do this:

Code: Select all

a:flipH():flipV()
But then again... with a3, it could be like the __mode of metatables, and you could use words with "h" and "v" in them if you wanted to flip it both ways.

Code: Select all

a:flip('valhalla')
a:flipX() and a:flipY() could work too I think.

a:flip(false, true) would be consistent with Quad:flip, buuut it's a bit hard to tell what's going on with that method.

Alternatively, you could just use skateboarding tricks.

Code: Select all

a:kickflip()
Then you could feel like you're playing Tony Hawk's Pro Skater.

I am unsure.

Re: Anim8: Vote your preferred flip method syntax

Posted: Sun Dec 02, 2012 10:50 pm
by Dattorz
I'm not a fan of having the flip() function do a toggle. Personally I think you should be able to pass a truth value that says whether or not you want the sprite flipped in that direction (this is how I'm doing it in my framework currently). It's easier to keep track of things this way - you don't need to know what the current flipped state is, you just tell it what you want it to be.

Re: Anim8: Vote your preferred flip method syntax

Posted: Mon Dec 03, 2012 5:36 am
by Inny
I haven't used anim8, but here's a question about one of the API functions:

Code: Select all

Animation:draw(image, x,y, angle, sx, sy, ox, oy)
Wouldn't supplying negative values in the sx and sy parameters already be enough to perform the flipping?

Re: Anim8: Vote your preferred flip method syntax

Posted: Mon Dec 03, 2012 9:08 am
by kikito
Inny wrote:I haven't used anim8, but here's a question about one of the API functions:

Code: Select all

Animation:draw(image, x,y, angle, sx, sy, ox, oy)
Wouldn't supplying negative values in the sx and sy parameters already be enough to perform the flipping?
Yes, but it's not a comfortable way of doing it. When flipping, both the scale and the offset have to be set. The scale is not too bad (-1 or 1 on each param) but the offset is a bit of a pain (-frameWidth or 0). Plus, if you want to be able to draw flipped animations with scale/offset, you have to be multiplying those values. I would make those calculations inside anim8.
Dattorz wrote:I'm not a fan of having the flip() function do a toggle. Personally I think you should be able to pass a truth value that says whether or not you want the sprite flipped in that direction (this is how I'm doing it in my framework currently). It's easier to keep track of things this way - you don't need to know what the current flipped state is, you just tell it what you want it to be.
I'm not sure I understand. None of the methods I described does "a toggle", they create a new animation. If this is not clear, I might need to change the names a bit more.

@santos: I liked most of your suggestions, thanks. FlipX and flipY sound nice. I agree that using 2 booleans is a bit confusing, and I'd rather avoid it.

Re: Anim8: Vote your preferred flip method syntax

Posted: Mon Dec 03, 2012 12:37 pm
by Nixola
I'd prefer a1 and/or a3 (maybe a3), but I don't use Anim8 (I don't like to use external libraries or modules)

Re: Anim8: Vote your preferred flip method syntax

Posted: Mon Dec 03, 2012 8:40 pm
by Robin
a4, without a doubt.

EDIT: I did not realise this was a poll topic (the poll got pushed off my screen), so please disregard my post.

Re: Anim8: Vote your preferred flip method syntax

Posted: Mon Dec 03, 2012 8:49 pm
by Puzzlem00n
a2 is kinda cool, but I feel a4 is a bit more flexible, so I'm going with that.

Thanks for putting this feature in, by the way, should be really helpful. Oh, and not to nag you, but you have a little typo in the vertical parts of the a1 and a2 examples. ;)

Re: Anim8: Vote your preferred flip method syntax

Posted: Mon Dec 03, 2012 10:52 pm
by kikito
Robin wrote:a4, without a doubt.

EDIT: I did not realise this was a poll topic (the poll got pushed off my screen), so please disregard my post.
Ah, but your commend provided some useful info. Some people voted for one option, but declared that they really didn't feel too strongly about it. You, on the other hand, chose a2 'without a doubt'. That is significant. May I ask why?

@Puzzledm00n, thanks, I've fixed the typos.

Re: Anim8: Vote your preferred flip method syntax

Posted: Tue Dec 04, 2012 4:05 am
by Garan
Hey cool, my question is getting new stuff added!
Anyway: I think of the choices a4 is the best, as it can easily just inserted into movement commands and the like. However, I was thinking something that might be a good idea would be a setDirection (or setXDirection and setYDirection) instead of a flipH() and flipY(). If you just have a flip like that, you might end up flipping twice when only once was needed. I was also wondering if there could be an optional parameter in anim8:draw that says which direction to draw. That way I can keep using my direction variables.