gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Stopping constant button presses...

#32540 - mr_square - Thu Dec 23, 2004 6:43 pm

In my game, when the player presses A, the character jumps. If you hold down A though, he keeps jumping. I'd rather have a 1 button press per jump system. I got it working on VBA using the code below, but on the actual hardware it doesn't work:

Code:


//A button is already intialised to 0


if(AButton == 0)
{
      if((!(*KEYS & KEY_A)))
      {
             AButton = 1;
      }
}
else if(AButton == 1)
{
      if((!(*KEYS & KEY_A)))
      {
          *KEYS = *KEYS | KEY_A;
      }
      else
     {
           tempAKey = 0;
     }
}


So basically it sets the AButton variable to 1 if the button is pressed. Then on the next frame it detects if the button was pressed - if it still is, it is cancelled, if not, the variable is reset to 0.

But as I said - it doesn't work on the hardware. The theory seems right - is it a problem with me trying to manually manipulate the KEYS register?

#32541 - sajiimori - Thu Dec 23, 2004 7:11 pm

This is answered in the FAQ.