Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Oktacon on January 26, 2015, 11:15:44 PM

Title: UISprite Animation, animations very fast when I go out of suspension in mobile
Post by: Oktacon on January 26, 2015, 11:15:44 PM
I have a problem with the UISprite Animation, i have a sprite in loop that to give click the play button in the editor displays the animation perfectly, but when I hit the pause button in the editor, i wait several seconds and I come out of the pause, the animation runs quickly until it reaches its normal movements.

I use the pause button to simulate the suspension in IOS or Android that i generated the same effect, that when you go back to the game the animation runs quickly and while more time has been in suspension more time delay in the animation reaches its natural movements, how can I fix this?
Title: Re: UISprite Animation, animations very fast when I go out of suspension in mobile
Post by: ArenMook on January 27, 2015, 04:38:02 AM
It's just how the script was written. It's a pretty simple script meant as an example more than anything. Check its Update() function -- it simply adds the delta time. It doesn't keep track of the application pausing. In your case, simply changing a single line is enough:
  1.         protected virtual void Update ()
  2.         {
  3.                 if (mActive && mSpriteNames.Count > 1 && Application.isPlaying && mFPS > 0)
  4.                 {
  5.                         mDelta += RealTime.deltaTime;
  6.                         float rate = 1f / mFPS;
  7.  
  8.                         if (rate < mDelta)
  9.                         {
  10.                                 // This right here:
  11.                                 mDelta = 0f; //(rate > 0f) ? mDelta - rate : 0f;
  12.  
  13.                                 if (++mIndex >= mSpriteNames.Count)
  14.                                 {
  15.                                         mIndex = 0;
  16.                                         mActive = mLoop;
  17.                                 }
  18.  
  19.                                 if (mActive)
  20.                                 {
  21.                                         mSprite.spriteName = mSpriteNames[mIndex];
  22.                                         if (mSnap) mSprite.MakePixelPerfect();
  23.                                 }
  24.                         }
  25.                 }
  26.         }
Title: Re: UISprite Animation, animations very fast when I go out of suspension in mobile
Post by: Oktacon on January 27, 2015, 11:28:31 AM
Thanks for responding, the solution was perfect, I hope also be useful for someone else.

Greetings and thank you very much.  :D