Author Topic: Issue with the UISpriteAnimation Reset() method.  (Read 2105 times)

2Nails

  • Guest
Issue with the UISpriteAnimation Reset() method.
« 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 ?
« Last Edit: April 11, 2013, 03:58:34 AM by 2Nails »

2Nails

  • Guest
Re: Issue with the UISpriteAnimation Reset() method.
« Reply #1 on: April 11, 2013, 02:43:58 AM »
Up
« Last Edit: April 11, 2013, 03:57:51 AM by 2Nails »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issue with the UISpriteAnimation Reset() method.
« Reply #2 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.         }

2Nails

  • Guest
Re: Issue with the UISpriteAnimation Reset() method.
« Reply #3 on: April 12, 2013, 02:49:00 AM »
It's working as expected.

Thank you very much.