c# - Menu Index onKey Issue -


language: c#

description: making small game in xna. creating menu game. have 3 menu menu states. 1= options menu, 2= start menu, 3=load menu. goal when user presses "d" key menu index increments 1 , "a" key, menu decrements. problem using keydown in xna updating each tick. when increment/decrement index, updates way fast. want user able switch menus without flickering extremely fast. below code, please let me know of solutions.

if(keyboard.iskeydown(keys.d))             {                     lyengine.game.menu_index++;                     if (lyengine.game.menu_index >= 3)                     {                         lyengine.game.menu_index = 1;                     }              }             else if (keyboard.iskeydown(keys.a))             {                 lyengine.game.menu_index--;                 if (lyengine.game.menu_index <= 1)                 {                     lyengine.game.menu_index = 3;                 }             } 

instead of changing menu index when key down need capture transition between key being on 1 tick , key being down on next.

to this, save previous value of key state , add condition:

if(keyboard.iskeydown(keys.d) && !keywasdown[keys.d]) {     // ... } keywasdown[keys.d] = keyboard.iskeydown(keys.d) 

you'll have create dictionary keywasdown store prior state.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

python - cx_oracle unable to find Oracle Client -