2D Toolkit Forum
2D Toolkit => Support => Topic started by: xecut on May 12, 2013, 03:00:04 pm
-
Hi ,
I know its not possible to play an animation when Time.timescale = 0...
Is there a way to implement Time.realtimeSinceStartup and play the animation?
I'm really trying to make an animation to play in a pause menu.
Thanks.
-
In tk2dAnimatedSprite.LateUpdate(), the animation is performed in this line
UpdateAnimation(Time.deltaTime);
If you just need this for one special sprite, etc. I suggest making a copy of the script, and then instead of Time.deltaTime, use time as used in tk2dUITime.cs.
-
Rather than duplicating the script, I just added a flag to tk2dSpriteAnimator like so:
tk2dSpriteAnimator.cs
/// <summary>
/// Interface option to make this animation ignore Time.timeScale
/// </summary>
public bool timescaleIndependant = false;
void LateUpdate()
{
UpdateAnimation(timescaleIndependant ? tk2dUITime.deltaTime : Time.deltaTime);
}
tk2dSpriteAnimatorEditor.cs
// Timescale Independant
bool newTimescaleIndependant = EditorGUILayout.Toggle("Timescale Independant", sprite.timescaleIndependant);
if (newTimescaleIndependant != sprite.timescaleIndependant) {
Undo.RegisterUndo(targetAnimators, "Sprite Anim Timescale Independant");
foreach (tk2dSpriteAnimator animator in targetAnimators) {
animator.timescaleIndependant = newTimescaleIndependant;
}
}
alternatively you might just subclass tk2dSpriteAnimator as say tk2dUISpriteAnimator
-
Is this a common requirement? If so I can add to the core system, but it seems awfully dependent on the game.
-
I think setting timescale to 0 when pausing the game is a fairly common technique. You often may want to have animated sprites as part of this paused UI which is where this comes into play.
I think it would probably be best to ad tk2dUISpriteAnimator rather than having this option show up on every sprite animator, as it is a somewhat special case. But I think it is a nice feature to have.
-
Now that the animator is independent to the sprite class itself, it does make sense to add a tk2dUIAnimator class in there. It'll be simple enough. Will be in the next version.