Tilengine - The 2D retro graphics engine forum
detect keyup - Printable Version

+- Tilengine - The 2D retro graphics engine forum (http://tilengine.org/forum)
+-- Forum: English forums (http://tilengine.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (http://tilengine.org/forum/forumdisplay.php?fid=7)
+--- Thread: detect keyup (/showthread.php?tid=1014)

detect keyup - INVOKER - 01-06-2021

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

RE: detect keyup - megamarc - 01-07-2021

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:

new = read()
if new == 1 and old == 0:
   keydown detected
elseif new == 0 and old == 1:
   keyup detected
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.

RE: detect keyup - INVOKER - 01-08-2021

oh ok, thank you i will give that a shot