button_down?(id)
in Window#update
. This will happen 60 times per second.Window#button_down
callback. This is how the Tutorial game handles the Escape key. This is called only once for the whole duration of holding the button.TICKS_PER_STEP = 30
def initialize
..
@countdown = 0
end
def update
..
if @countdown > 0 then
@countdown -= 1
# Second, third… step
if @countdown == 0 and button_down? Gosu::KbLeft then
@countdown = TICKS_PER_STEP
move_left
end
end
..
def button_down(id)
if id == Gosu::KbLeft and @countdown == 0 then
# First step
@countdown = TICKS_PER_STEP
move_left
end
end
TICKS_PER_STEP
even if they hammer the left key. If the speed of movement should be unrestricted for hammering keys, then you can just reset @countdown
in the button_up(id)
callback.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill