c# - Flipping a boolean value -
i have small c# problem i'm sure must easy solve, can't life of me figure out what's wrong.
i have debug mode in game turned on when boolean value debugmode set true. variable held within gameinfo object, referenced in gameinfo class. want make can toggle debug mode on , off pressing "i" key on keyboard. here's tried:
if (keyboardstate.iskeydown(keys.i)) gameinfo.gameinfo.debugmode = !gameinfo.gameinfo.debugmode;
the problem nothing happens when press "i". if following able turn debug mode off know idea works:
if (keyboardstate.iskeydown(keys.i)) gameinfo.gameinfo.debugmode = false;
does know i'm doing wrong? can of course solve using couple of if statements turn true false , vice versa, long-winded compared simple statement above.
thanks lot can offer :)
this require have flag, prevent key event being handled multiple times @ once.
bool keypressregistered = false; ... if (keyboardstate.iskeydown(keys.i) && !keypressregistered) { keypressregistered = true; gameinfo.gameinfo.debugmode = !gameinfo.gameinfo.debugmode; } ... keypressregistered = !(keypressregistered && keyboardstate.iskeyup(keys.i));
Comments
Post a Comment