0

How can I make blink/flash buttons in a series?

I'm designing a game (for my college class) that is similar to Simon, where the user must correctly push the buttons in the same order that they were flashed by the computer. All my buttons blink simultaneously with the following code:

blinkEffect(btn1);
blinkEffect(btn2);
blinkEffect(btn3);

I have tried using wait(500) inside of a try/catch, but the emulator didn't like it. It produced an error that the program was stopping.

Any advice is much appreciated.

juseniah
  • 1
  • 1
  • 1
    Take a look at https://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay-in-android – Ryan M Jun 30 '20 at 20:38

1 Answers1

0

If they're all blinking at the same time, presumably your shooting off three separate threads at once ... hence they all appear to start at almost exactly the same time.. you'd need something like:

blinkEffect(btn1);
Thread.sleep(blinkEffectDuration);
blinkEffect(btn2);
Thread.sleep(blinkEffectDuration);
blinkEffect(btn3);
// complete

Ideally you'd wrap this up in a for loop and the sequence of buttons would be in a List.

Rob Evans
  • 2,822
  • 1
  • 9
  • 15
  • Would you please clarify what you meant by putting the buttons in a list? Thanks for the tips! – juseniah Jul 01 '20 at 18:17
  • something like: `List – Rob Evans Jul 01 '20 at 22:33