Tilengine - The 2D retro graphics engine forum

Full Version: detect keyup
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello again, im wondering what is the best way for detecting a keyup and if theres a function for that in tilengine? im making a ui element but of course when detecting input it just ends up going to the bottom of and top of the list really fast. And is there a tilenegine discord? i dont want to clog the forums with small questions lol
Hi again,
Tilengine reports current button state. Detecting keydown or keyup involves detecting state transitions. For that you must keep previous value and compare it to current value, then reassign current to previous and process next frame. In pseudocode:


Code:
new = read()
if new == 1 and old == 0:
   keydown detected
elseif new == 0 and old == 1:
   keyup detected
endif
old = new

I don't have discord, but don't worry about posting small questions here Smile that's the point of the forum, to answer questions.
oh ok, thank you i will give that a shot