2D Toolkit Forum
2D Toolkit => Support => Topic started by: Neeko on January 25, 2014, 07:22:37 pm
-
I have a cooldown timer sprite animator whose animation clip I want to play for a variable number of seconds. So for example one instance the animation clip will take 60 seconds to complete, or take 10 seconds to complete.
I know of the ClipFps property, and I've been fiddling around with it's value, but I can't seem to figure out what I should be setting it at based on the number of seconds I want the clip to take.
Here's a code sample, maybe there's a better way to do this?
// Take 60 seconds to cooldown.
CooldownTime = 60f;
StartCoroutine(CooldownTimer());
private IEnumerator CooldownTimer() {
cooldownSprite.Play("cooldown");
cooldownSprite.ClipFps = CooldownTime;
CooldownFinished = false;
yield return new WaitForSeconds(CooldownTime);
cooldownSprite.Play("ready");
CooldownFinished = true;
}
-
No that is probably the best way to do it. The clip fps will change the rate the animation is playing, I don't think thats what you want?
-
I do want to change the rate the animation clip is playing; the sprite is simply a circle with an animation clip that fills itself in of the course of 13 frames. Sometimes I'll want the circle to fill in a faster rate (example, take 10 seconds to complete the animation), other times at a slower rate (60 seconds to complete the animation).
-
The coroutine is the best way to do this.
-
Right, but the issue I'm having is with this line
cooldownSprite.ClipFps = CooldownTime;
If CooldownTime is n, as to represent n seconds, what should I set ClipFps to so that the cooldownSprite animation clip also takes n seconds to complete?
-
No, that will be how many frames per second. Setting it to N will mean it will play N frames in one second. You need to check the number of frames in the clip, then work out fps based on that. So number of frames / number of seconds.
-
Ah, perfect. Kind of obvious, embarrassed I didn't figure that out myself :-[
Thanks again!