Hey guys, new on here but I did post an introduction in the new members place
OK, so my problem, I'm working on what is to be a bit of a basic game engine, not really for much in particular, just an assignment I have for my final year at university. A lot of what I have so far works OK, but for some reason key presses are not being recognised, maybe because I'm doing it in a silly way I realise or I just made a simple error, and its one of those things I've sat staring at for so long now that I cant see what's wrong.
This is the keyAdapter I made, I used it as a bit of an interface so I could add different control schemes later on
@Override public void keyPressed(KeyEvent e) { keys.add(e); } @Override public void keyReleased(KeyEvent e) { remove(e); } private void remove(KeyEvent e) { for(int i = 0; i < keys.size(); i++) { if(keys.get(i).getKeyCode() == e.getKeyCode()) { keys.remove(i); } } }
Here is a part of a controls class that actually states what keys are and what they do, I did try using if(keys.contains(KeyEvent.VK_MINUS)) to just check if that keyEvent is stored but that didn't work for some reason
if(isPressed(KeyEvent.VK_MINUS)) { GlobalVariables.numBirds--; } private boolean isPressed(int e) { ArrayList<KeyEvent> keys = Input.get().getKeys(); for(int i = 0; i < keys.size(); i++) { if(keys.get(i).getKeyCode() == e) { return true; } } return false; }
hmm, cant think what else may be the problem, if anyone else has any ideas please say and Ill get whatever code you wish to see
Thank you for your time regardless of whether you know what my problem is or not