We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey, I already know people have made solutions to this problem but I was wondering if anyone knew a Library for diagonal movement, Ideally can detect multiple keys pressed at once but I'll take anything you got ;)
Another quick question, I know that Processing/Java uses key/keyCode which is a primitive variable and why only one value can be detected at once but why do we stick with that? Is there a reason they haven't changed it because native diagonal movement/multiple keyPress detection has been a fair majority community's wishlist for quite a while now. Thanks for the help! :)
Answers
One way I've done this in the past is to keep track of all the keys pressed in an array. Currently down keys can be checked for being pressed with keys[' '] and fresh key presses can be detected with keyHit(' '). I do some math in setKey that makes upper and lower case interchangeable as well.
I don't think it's complex enough to be worthy a library. But maybe there's one.
Here is my simplified version of the code above:
Another option: you can also implement a list of active keys (as in the solutions above) using a HashMap rather than an array. It may not make much difference for basic setups, but it has one advantage that it isn't constrained to 256 values -- it tracks any keycode no matter what it is and puts it in the map.
https://forum.processing.org/two/discussion/comment/122623/#Comment_122623