java – How to integrate button event into game loop


I’m making a tower defense game.

Scenario:

  1. Press button -> enable tower building
  2. Click mouse anywhere in game area -> make a tower

Problem is EDT is ahead of game loop, so tower will be place simulaneously as clicking the button.

At least that is what Im guessing. So how to decouple these events? How to let the game loop handle button listening instead of EDT?

Sorry for my newbieness.

EDIT: I need to modify an array list while looping over it. Button listener will add an element, while game is looping over it…



Source link

Leave a Comment