Changing delay times 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
Cowinatub
Prole
Posts: 9
Joined: Fri Nov 09, 2012 6:13 am

Changing delay times in anim8

Post by Cowinatub »

been looking through anim8 to see if its the kind of library I'm looking for, and I cant seem to find any functions to change the delay time of an animation after its been created, even though it mentioned that there might be in the read me. Is there a way to do this, if so, how?
Cowinatub
Prole
Posts: 9
Joined: Fri Nov 09, 2012 6:13 am

Re: Changing delay times in anim8

Post by Cowinatub »

24 hour bump.
Cowinatub
Prole
Posts: 9
Joined: Fri Nov 09, 2012 6:13 am

Re: Changing delay times in anim8

Post by Cowinatub »

Anyone?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Changing delay times in anim8

Post by kikito »

Please don't bump forum posts. It's not well perceived in this forum.
Cowinatub wrote:Change the delay time of an animation after its been created
Why do you think you need to do that? What, exactly, are you trying to accomplish?
Cowinatub wrote:even though it mentioned that there might be in the read me.
What part of the readme are you referring to? Maybe I'll need to edit it.
When I write def I mean function.
Cowinatub
Prole
Posts: 9
Joined: Fri Nov 09, 2012 6:13 am

Re: Changing delay times in anim8

Post by Cowinatub »

I was planning on having the animation speed up and slow down depending on how fast the player is moving. Sorry about bumping, It's just that I was starting to get pretty desperate for an answer as the project I'm working on has a deadline which is starting to get pretty soon.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Changing delay times in anim8

Post by Jasoco »

kikito wrote:Please don't bump forum posts. It's not well perceived in this forum.
To be fair he did wait 23.5 hours the first time. But I'd say rule of thumb is if your thread is still on the first page, don't bump it. Unless its been days and you have new information to add that just wouldn't work with your last post and you want people to know you added something. Not when you're bumping it just to beg people to answer your question. (Let alone twice in a short period of time. That's a no-no.)

Believe me, if someone has an answer, they'll post it. The forum is set up to let us know exactly what threads have posts we haven't seen yet, even if it was posted months ago. There have been times I've gone away and came back here to find threads with new posts all the way back 7 or 8 pages that I had to read through.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Changing delay times in anim8

Post by kikito »

I would have answered before, but I was kindof busy and on saturday the forums were offline (at least for me).

I knew several ways to do this, but I didn't know which one was better until I read Cowinatub's answer:
Cowinatub wrote:I was planning on having the animation speed up and slow down depending on how fast the player is moving.
Cowinatub: There's a way to change the delays of each animation frame - each animation has an attribute called delays (animation.delays), which is just an array of durations. You could manipulate that array and change the speed of each frame however you wanted.

But there is a much better way of doing what you want, without having to go over each frame.

Let me explain: Chances are that you already have a "velocity" somewhere in your code. A number that says how fast the player/enemy/etc is moving. If you don't have a number (i.e. you have two numbers, one for vx and another for vy) you need want to get it somehow (i.e. only using vx and ignoring vy, or getting the length of the vector). Normally this velocity will come in pixels per second (px/s), although the units will not appear in your code. We can call this "self.velocity".

The next thing you need to determine is what velocity is the "standard" - the one in which the animation "looks good" by default, with no modifications. It should be a number: 20 px/s, 30 px/x, whatever. We can call this "animationVelocity"

Then you need to know "how fast you are moving with regards to the sandard velocity" at any given time. This is also a number. It will be 1 when velocity == animationVelocity. If velocity is twice as fast as the animation, it will be 2. And if it's half, it will be 0.5. In other words, this variable, which we can call velocityCoefficient, is self.velocity / animationVelocity.

Now here is the kick: Every time you update the animation, take the velocityCoefficient, and multiply it by dt before giving it to the animation.

So if before you had this:

Code: Select all

animation:update(dt) -- I do this for all velocities
Now you have this:

Code: Select all

local animationVelocity = 30
...
local velocityCoefficient = self.velocity / animationVelocity
animation:update(dt * velocityCoefficient) -- I update faster/slower depending on my velocity
To simplify things up, I recommend you to set the same animationVelocity for all your animations. Otherwise, you will have to replace animationVelocity with self.animationVelocity, and update it every time you change animations.

I hope this helps, good luck with your project.
When I write def I mean function.
Cowinatub
Prole
Posts: 9
Joined: Fri Nov 09, 2012 6:13 am

Re: Changing delay times in anim8

Post by Cowinatub »

Thanks for the help!
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 2 guests