c# - Keyhandler cannot detect key -
c# - Keyhandler cannot detect key -
hello got problem keyhandler. pretty much want function observe if key pressed.
public bool keyhandler(keys key) { if(key != null) { if (keyboard.getstate().getpressedkeys() == key) { homecoming true; } else { homecoming false; } } else { homecoming false; } }
the problem lies
if (keyboard.getstate().getpressedkeys() == key)
i don't know how how check if key pressed , how pass key in function.
the error get: "operator '==' cannot applied oparands of type microsoft xna.framework.input.keys[] , microsoft.xna.framework.input.keys" using c# , xna
i don't why doesn't work.. can 1 help me?
keyboardstate.getpressedkeys()
returns array of keys(keys[]
). gets pressed keys, handy if have sort of keymanager or textbox or something.
what need this(like sebastian l said):
keyboardstate ks = keyboard.getstate(); // keyboard's state if (ks.iskeydown(keys.a)) { dosomereallyinterestingstuff(); }
ks.iskeydown(keys key)
returns true if key down. here's improve method:
class inputmanager { keyboardstate state; // phone call every update public void update() { state = keyboard.getstate(); } public bool iskeydown(keys key) { homecoming state.iskeydown(key); // or homecoming key == null ? false : state.iskeydown(keys.key); // never phone call method null key, that'd stupid. } }
c# xna
Comments
Post a Comment