Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Two gamepad buttons at once?
- - By max_n_ruby Date 2017-05-24 22:37
Can you do it? Press two gamepad buttons at once? I want to press a direction on the D pad and press a button and have something happen.

I've tried

def button_down(id)
  if id == Gosu::GP_BUTTON_1 and Gosu::GP_RIGHT
    #do thing
  end
end


and I've tried

def button_down(id)
  case id
    when (Gosu::BUTTON_1 and Gosu::GP_RIGHT)
      #do thing
    end
end


When I run the code it does #thing only when I press the second button. The buttons don't seem to work together. The one that fulfills the if/then statement or the case statement is the last thing. ie: Gosu::GP_RIGHT

Is this a limitation of ruby? Or Gosu?
Or am I not getting something?
Parent - - By RunnerPack Date 2017-05-25 03:13
The button IDs aren't bit-masks, so they can't be boolean'd with each other. The Window#button_down callback is called for each button press, and receives a single id. The id will only ever equal one key/button. You have to check if the id is one of the buttons in the combo, then check to see if the other button is also held down (with Gosu#button_down?(id)).
Parent - By max_n_ruby Date 2017-05-25 21:32
Ok. that makes sense. I'll give it a try.
Thx :)
Up Topic Gosu / Gosu Exchange / Two gamepad buttons at once?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill