is there a way to register a double tap on the same button?
i want to make it such that on the first key press, my character walks, but if the player lets go and quickly taps the same button again, the character runs
it doesn’t seem to be asked on the forums and i didn’t see it in the manual
well i might have searched the wrong terms on forum search function and missed out soem part in the manual…maybe, but i couldnt find any info on this
You can do this, but you have to write the code to do it yourself, for instance by checking globalClock.getFrameTime() each time you receive the button-press event, and checking to see if it is very close in time to the last time you received the same button-press event.
well thats saddening, so i have to set a time frame, like half a second
and within this time, if the key is down, and down again, it is detected as a double key press?
Yes, it’s easy to do. Something like this:
now = globalClock.getFrameTime()
elapsed = now - self.lastKeyEvent
self.lastKeyEvent = now
if elapsed <= 0.5:
in the manual I see this code:
print "repeat a",a
doesn’t that make the same work laperen asked for?
Repeat isn’t used for double-pressing. The repeat event is fired repeatedly if the button is held down.