People here keep suggesting to me to use Key Bindings in my Java 2D games instead of Key Listener.
So I learned it and I'd like to know wether I understand correctly how to use it.
Let's say I have a game, with two playes, each player can push 5 buttons.
Player 1:
- UP arrow - move forward
- LEFT arrow - change angle of movement
- RIGHT arrow - change angle of movement
- SPACE key - fire missile
- L key - fire secondary missile
Player 2:
- W key - move forward
- A key - change angle of movement
- D key - change angle of movement
- CAPS-LOCK key - fire missile
- 'Z' key - fire secondary missile
If I want the program to react differently to each one of the different key-presses, than this is what I have to do: (?)
- Create 10 new nested classes extending AbstractAction, inside the class that runs most of the game logic.
- Create an instance of every one of these 10 new classes, and bind each one to a key.
Is this correct? Is it really logical to create 10 new classes only for pushing buttons? I want to know if I understand correctly how to use Key Bindings, so I can start programming with it.
Thanks