Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: 2Nails on April 10, 2013, 10:02:19 AM

Title: Issue with the UISpriteAnimation Reset() method.
Post by: 2Nails on April 10, 2013, 10:02:19 AM
Hi !
I'm having an issue with the UISpriteAnimation Reset() method.

Right now, I have a Button. When my mouse is on top of it (without clicking), it starts playing an animation, using the UISpriteAnimation script.
And when I stop being on the top of it, the animation stops and stays at its current frame. If my mouse get back on the top of it, the animation plays agains, starting from where it stopped.

Now here's my problem. I would like the animation to go back to the first frame when I stop being at the top.
So, I simply added
  1. ...GetComponent<UISpriteAnimation >().Reset();
to my script.

But, what it is currently doing is : When i stop being at the top, the animation still stops at its current frame. And its only when I get back on the top of it, that the animation plays, starting from frame 1.
And this, even though this line
  1. ...GetComponent<UISpriteAnimation >().Reset();
has been precisely put on the part where it should act when I leave the button.

What I understand it does is that, (and I could likely be wrong, correct me)  the UISpriteAnimation prepare to switch to the frame 1 from the current frame, but actually wait that the current frame timer's end to do it.
But, I'm also disabling the whole UISpriteAnimation, in the following line of the code, so it actually never switch to frame 1 until I go back on top of the Button, (enabling UISpriteAnimation).


Ok I'm sorry, the whole explanation of my issue is quite messy. Here is the script, might be clearer.

  1. void OnHover (bool isOver) {
  2.        
  3.                         if (isOver)
  4.                         {
  5.                                 Debug.Log("true");
  6.                                 Target.GetComponent<UISpriteAnimation>().enabled = true;
  7.                                 Intermediaire.transform.localScale = new Vector3(0.125f, 0.125f, 1.0f);
  8.                                 Intermediaire.transform.localPosition = new Vector3(-35.0f, 13.0f, -13.0f);
  9.                         }
  10.                         else
  11.                         {
  12.                                 Debug.Log("false");
  13.                                 Target.GetComponent<UISpriteAnimation>().Reset();
  14.                                 Target.GetComponent<UISpriteAnimation>().enabled = false;
  15.                                
  16.                         }
  17.  

How do you think I could proceed in order to Reset(); and then instantely display the following frame (the first frame) before disabling the UISpriteAnimation ?
Title: Re: Issue with the UISpriteAnimation Reset() method.
Post by: 2Nails on April 11, 2013, 02:43:58 AM
Up
Title: Re: Issue with the UISpriteAnimation Reset() method.
Post by: ArenMook on April 11, 2013, 09:10:53 PM
Modify UISpriteAnimation's Reset function to:
  1.         public void Reset()
  2.         {
  3.                 mActive = true;
  4.                 mIndex = 0;
  5.  
  6.                 if (mSprite != null && mSpriteNames.Count > 0)
  7.                 {
  8.                         mSprite.spriteName = mSpriteNames[mIndex];
  9.                         mSprite.MakePixelPerfect();
  10.                 }
  11.         }
Title: Re: Issue with the UISpriteAnimation Reset() method.
Post by: 2Nails on April 12, 2013, 02:49:00 AM
It's working as expected.

Thank you very much.