Hello Guest

Author Topic: Playing tk2dAnimatedSprite when Time.timeScale = 0?  (Read 7194 times)

xecut

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Playing tk2dAnimatedSprite when Time.timeScale = 0?
« 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Playing tk2dAnimatedSprite when Time.timeScale = 0?
« Reply #1 on: May 12, 2013, 05:19:24 pm »
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.

netpro2k

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Playing tk2dAnimatedSprite when Time.timeScale = 0?
« Reply #2 on: June 22, 2013, 07:44:59 am »
Rather than duplicating the script, I just added a flag to tk2dSpriteAnimator like so:

tk2dSpriteAnimator.cs
Code: [Select]
/// <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
Code: [Select]
// 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

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Playing tk2dAnimatedSprite when Time.timeScale = 0?
« Reply #3 on: June 22, 2013, 04:14:08 pm »
Is this a common requirement? If so I can add to the core system, but it seems awfully dependent on the game.

netpro2k

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Playing tk2dAnimatedSprite when Time.timeScale = 0?
« Reply #4 on: June 22, 2013, 11:50:41 pm »
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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Playing tk2dAnimatedSprite when Time.timeScale = 0?
« Reply #5 on: June 23, 2013, 12:55:30 am »
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.