Author Topic: Prevent second Buttonpress  (Read 5983 times)

BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Prevent second Buttonpress
« 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?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Prevent second Buttonpress
« Reply #1 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.

BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Re: Prevent second Buttonpress
« Reply #2 on: August 28, 2013, 12:51:21 PM »
Same procedure with OnPress? The Button works with the OnPress(bool pressed) method.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Prevent second Buttonpress
« Reply #3 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).

BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Re: Prevent second Buttonpress
« Reply #4 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?

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Prevent second Buttonpress
« Reply #5 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
 }
}