How to do the following with the least code possible?
-> After holding a certain key down for one second, do stuff
Now of course you can create a variable, increment that variable by delta time, and if that variable > 1, then do stuff, like
int ticks = 0;
public void foo(float delta) {
if(keyDown)
ticks += delta;
if(ticks > 1) doStuff();
}
}
But I find that code clunky and adds variables to the class that I don’t really like.
Is there a more elegant way of doing it? (And btw I’m using kotlin language so don’t be afraid to post the possibilities in that language)