Author Topic: UISprite Animation, animations very fast when I go out of suspension in mobile  (Read 2181 times)

Oktacon

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 1
    • View Profile
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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
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.         }

Oktacon

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 1
    • View Profile
Thanks for responding, the solution was perfect, I hope also be useful for someone else.

Greetings and thank you very much.  :D