if button_down?(KbDown) and !@pressed
@index+=1
@pressed=true
elsif not button_down?(KbDown)
@pressed=nil
enddef button_down(id)
if id==KbDown then @index+=1 end
end
button_down is a method that you write and wait for Gosu to call it whenever a button is pushed down.button_down? is a method that you call to ask Gosu whether a button is being held down right now. Gosu never calls button_down?.button_down is what you use for one-time button presses, and button_down? is what you use to make buttons influence code in update - for example, walking left and right is a case for button_down? because you don't want the player to move only one pixel when he first hits the button, but you want them to move in every update tick.class MyWindow ...
def button_down(id)
if id == Gosu::KbDown then
move_down_in_menu...
end
end
class YourWindow < Gosu::Window
def update
end
def draw
end
def button_down(id)
end
end
button_down(id) on the GameManager too. It's just a Ruby method call, no magic :)
Powered by mwForum 2.29.0 © 1999-2013 Markus Wichitill