Configurable controls
in
Programming Questions
•
1 year ago
I was wondering what an efficient way to make configurable controls would be? I was hoping to have it so that in the controls menu when you clicked on one of the configurable controls it would change color (or something like that) and then wait for a button press which it would then retrieve the ASCII value of and would set that to be the control it uses. Most games do it this way and i was wondering how i could do this in processing.
Currently i can only think of using this code:
- boolean upValue = false;
- string upControl = "";
- boolean wKey = false;
- boolean upKey = false;
- void draw(){
- switch(upControl){
- case wKey:
- upValue = wKey;
- break;
- case upKey:
- upValue = upKey;
- break;
- }
- }
- }
- void keyPressed(){
- if (key == 119){
- wKey = true;
- }
- if (keyCode == up){
- upKey = true;
- }
- }
- //repeated for keyReleased() but with false instead of true
And then of course i would have some way of changing upControl in game through the menu (which i will figure out the code for later)
Is there atleast a way to simplify it a little by switching the "switch / case" statement for some sort of statement that will automatically set the value of "upValue" to the value of the variable that is named in string "upControl" instead of having to put a case for every key and for every control?
1