I have a "GUI" and need that it recognizes "keyboard"

Started by Mariano Cirigliano, Fri 29/10/2010 23:00:52

Previous topic - Next topic

Mariano Cirigliano

I have a "GUI" and need that it recognizes "keyboard"

On having touched the letter "S" I need that it is opened " QUITGAME (0);

On having touched the letter "N" I need that one comes back to the game.

I hope that my question is understood.

Thanks to all!. ???

mode7

I would do it like that

function repeatedly_execute() {
if (gYOURGUI.Visible == true)
    {
     if (IsKeyPressed (eKeyS) == true) QuitGame(0);
     if (IsKeyPressed (eKeyN) == true) gYOURGUI.Visible == false;
    }
}

monkey0506

You don't have to use repeatedly_execute. In fact it's probably less efficient than just using on_key_press since you're duplicating a check done internally. Do something like this:

Code: ags
function on_key_press(eKeyCode keycode) {
  if (IsGamePaused()) { // game is paused, ignore most keys
    if (gYourgui.Visible) {
      if (keycode == 'S') QuitGame(0);
      else if (keycode == 'N') gYourgui.Visible = false;
    }
    // else..other GUIs that need to pause the game but intercept keypresses
  }
  // ...the rest of your normal keypresses here
}

SMF spam blocked by CleanTalk