Author Topic: UISpriteAnimation frame rate  (Read 3204 times)

Nicky

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
UISpriteAnimation frame rate
« on: September 24, 2014, 10:29:16 PM »
I'm doing a countdown animation with 24 sprites that are supposed to animate completely for every second in the countdown. The FPS is also set at 24.

I have already set up the animation to play, but somehow the sprites only play til about frame 18. I checked that the scene FPS fluctuates around 50 to 100. How do I make sure that it plays up til frame 24 for every second that passes?

Thanks in advance for any input.

  1. UISpriteAnimation SpriteCountdown;
  2. UILabel LabelCountdown;
  3.  
  4.                 public IEnumerator StartCountdown(int seconds) {
  5.                         SpriteCountdown.ResetToBeginning();
  6.                         SpriteCountdown.Play();
  7.                         LabelCountdown.text = seconds.ToString();
  8.                         for (int i=seconds;i>=0;i--) {
  9.                                 yield return new WaitForSeconds(1);
  10.                                 LabelCountdown.text = i.ToString();
  11.                                 if (i>0) {
  12.                                         SpriteCountdown.ResetToBeginning();
  13.                                         SpriteCountdown.Play();
  14.                                 }
  15.                                 else {
  16.                                         SpriteCountdown.Pause();
  17.                                 }
  18.                         }
  19.                 }
  20.  

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UISpriteAnimation frame rate
« Reply #1 on: September 25, 2014, 02:44:43 AM »
If you're using SpriteAnimation it should handle itself.

  1. void StartAnimation()
  2. {
  3. mySpriteAni.framesPerSecond = 24;
  4. mySpriteAni.Play();
  5. }
  6.  
Just remember to have the reference to mySpriteAni set to the UISpriteAnimation.

Nicky

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: UISpriteAnimation frame rate
« Reply #2 on: September 25, 2014, 02:54:28 AM »
If you're using SpriteAnimation it should handle itself.

  1. void StartAnimation()
  2. {
  3. mySpriteAni.framesPerSecond = 24;
  4. mySpriteAni.Play();
  5. }
  6.  
Just remember to have the reference to mySpriteAni set to the UISpriteAnimation.

Thanks! Setting the fps before each Play() did the trick.

I wonder what the "Framerate" property in the inspector for then?