Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: BehindTheStone on August 28, 2013, 12:01:38 PM

Title: Prevent second Buttonpress
Post by: BehindTheStone on August 28, 2013, 12:01:38 PM
So I have a button and when this button is pressed it's playing a certain Animation (2DToolkit), but when the button is pressed again, the animation starts again before the last cycle of the animation could end.

Is there a way to prevent more input on the button till the moment the animation is done playing?
Title: Re: Prevent second Buttonpress
Post by: Nicki on August 28, 2013, 12:34:59 PM
You'll have to do a little work.

Wherever you're processing your OnClick(), you should set a bool (animating). When the toolkit animation is done, call a method on your OnClick handler to set animating to false.
Title: Re: Prevent second Buttonpress
Post by: BehindTheStone on August 28, 2013, 12:51:21 PM
Same procedure with OnPress? The Button works with the OnPress(bool pressed) method.
Title: Re: Prevent second Buttonpress
Post by: Nicki on August 28, 2013, 01:01:03 PM
Yeah, well, OnPress has the down/up bool sent with it, but the idea is the same. Just make sure you only fire your animation on the one you want (pressdown or release).
Title: Re: Prevent second Buttonpress
Post by: BehindTheStone on August 28, 2013, 01:09:48 PM
Mhm, to be honest I didn't quite understand how to prevent the second input with the animation-bool?
Some Pseudo-Code-Advice?
Title: Re: Prevent second Buttonpress
Post by: ENAY on August 28, 2013, 10:16:58 PM
What Nicky said. PsuedoCode? Something like this maybe.



bool isAnimPlaying = false;

if (OnPress)
{
 if (!isAnimPlaying)
 {
  PlayAnim();
  isAnimPlaying = true;
 }

 if (IsAnimFinished())
 {
  isAnimPlaying = false
 }
}