Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My team and I are currently developing a 2D platformer with SDL/OpenGL and we want to add support to the Xbox360 Gamepad with the XInput library from Microsoft, but we are currently having a problem.

First of all, the method for reading the key states it's this one:

bool InputMapping::Gamepad::checkKeyState(WORD button)
{
  DWORD dwResult;
  DWORD idPlayer = playerID - 1;

  XINPUT_STATE state;
  ZeroMemory( &state, sizeof(XINPUT_STATE) );

  dwResult = XInputGetState( idPlayer, &state );

  if ( state.Gamepad.wButtons & button)
  {
    return true;
  }

  return false;
}

This method returns true or false if the selected key it's pressed or not.

But it seems that the polling of the keys it's ocurring really fast, in the menus, moving through the buttons it's really fast and I can't controlled.

There is a way to limit the time between polling inside of the XInput or I should do it by myself? or what you recommend me?

If I didn't explain me clearly don't hesitate in say that.

Thanks a lot.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

There is a good reason why polling of controls is fast. Finally it is the only way the user can take action in your game. ;-)

Ok, now the (hopefully) non obvious part: You could either require the user to press and release the button to navigate in the menus. For that you would store a boolean flag if button is pressed and fire your "clicked" event after button is released again.

Same thing could be done by storing game/system time and firing clicked event every x ms.

In both cases I would recommend using this method only in menus and not for controlling the actual game character since that would result in serious lagging.

share|improve this answer
    
Thanks a lot for this great comment, I implemented the released key method and works perfectly. –  oscar.rpr Jan 2 '12 at 14:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.