c# - XNA - Freezing Menu Error -
when click down arrow gets stuck on second selection , or down no longer work, how fix that?
second question: how prevent freezing when changing menu items? when change menu items, freezes of second selection. here code concerning question;
keyboard = keyboard.getstate(); mouse = mouse.getstate(); if (keyboard.iskeyup(keys.up) && prevkeyboard.iskeydown(keys.down)) { if (selected > 0) selected--; else selected.equals(buttonlist.count - 1); } if (keyboard.iskeyup(keys.up) && prevkeyboard.iskeydown(keys.down)) { if (selected < buttonlist.count - 1) selected++; else selected.equals(0); } prevmouse = mouse; prevkeyboard = keyboard; }
the original code had, after being modified worked fine me. here modifications:
public void update(gametime gametime) { keyboard = keyboard.getstate(); mouse = mouse.getstate(); if (checkkeyboard(keys.up)) { if (selected > 0) selected--; else{selected = buttonlist.count - 1;} } if (checkkeyboard(keys.down)) { if (selected < buttonlist.count - 1) selected++; else {selected = 0;} } prevmouse = mouse; prevkeyboard = keyboard; } public bool checkmouse() { return (mouse.leftbutton == buttonstate.pressed && prevmouse.leftbutton == buttonstate.released); } public bool checkkeyboard(keys key) { //here thing needed changed, based on original post //you checking if both keys down originally, meaning // true while button pressed. if previous keyboard down, //and current keyboard up, means button released. return (keyboard.iskeyup(key) && prevkeyboard.iskeydown(key)); }
Comments
Post a Comment