Author Topic: Non-looping UISpriteAnimation  (Read 3328 times)

doggan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Non-looping UISpriteAnimation
« on: July 01, 2012, 05:54:38 AM »
I purchased NGUI a few weeks ago, and I am extremely pleased! It is very well designed and easy to use. Thanks for the great library.

In addition to my UI and gameplay, I am using NGUI for all of my particle effects.

For example, an explosion effect has 5 frames of animation data. Using UISpriteAnimation, I can get the desired effect I want.

However, it was not perfect, so I made changes locally to the NGUI library in order to get the behavior I want. My question is: Is there a better way to do this? If not, is it possible to request this type of functionality for a future version of NGUI?

Here is what I added:
  • Ability to set a non-looping UISpriteAnimation (single-shot) - The explosion should play once and then stop.
  • Public interface to query for when the animation is done playing - When the explosion is done playing, some other code looks at the “IsDone” flag and destroys the particle effect. (This could also be done with SendMessage, but I opted with the flag for performance reasons).
  • Public interface for resetting the animation to the first frame - All of my particle effects are pooled, so when an explosion is destroyed, it is recycled and used later, so I need to reset the animation.

Is this the correct way to approach this, or is there a better way? If not, is it possible to request this functionality?

Thanks for reading!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Non-looping UISpriteAnimation
« Reply #1 on: July 01, 2012, 11:19:33 AM »
When designing this feature back in the day I skimmed over it thinking "meh, no one will want to use NGUI like it's 2D Toolkit"... I can ask Phil to take a look into adding these features next week (good suggestions btw!).

doggan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Non-looping UISpriteAnimation
« Reply #2 on: July 02, 2012, 08:06:31 AM »
Awesome! Thanks for the quick response.

doggan

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Non-looping UISpriteAnimation
« Reply #3 on: July 20, 2012, 07:03:44 AM »
Thank you for adding this functionality to the 2.1.0 release. :D

However, I tried to use it and I think it is bugged.

In UISpriteAnimation.cs, this:
  1. public bool isDone { get { return mActive; } }

... should be this:
  1. public bool isDone { get { return !mActive; } }

Making this change, it seems to work perfectly.

(Or, the accessor should be renamed from "isDone" to "isPlaying" or "isActive").

Thanks!

PhilipC

  • Guest
Re: Non-looping UISpriteAnimation
« Reply #4 on: July 20, 2012, 09:49:44 AM »
Property is now named isPlaying. Thanks.