Multi-Key input registered after key release
I was working on a game and kept running into an issue where if you press two arrows keys at once, the game would sometimes register both of the key press BUT only after you released one of the keys. Say you pressed the down key, then pressed the right key, if you released the down key the character would move in a down-right fashion.
I was having the same problem with that. I was wondering if it had something to do with the way that the check for input statements were set up. I was thinking that it might be better if there was a built in function that could be used that would check for which keys are pressed and the user could check for that.
@dispositional There is exactly that available, if you really want to do the key checking on your own: http://melonjs.github.io/docs/me.event.html#KEYDOWN
This is the first that I've heard of this issue; which melonJS version are you using? And @wheelerau which version are you using?
I am using version 2.0.2. I went off the tutorial from melonjs.org when I made mine, even on that one I noticed that one of the direction keys would always take precedence over the other when switching between them. I think that there could be a way around this, it might just need to be done in the entities.js file though.
Key precedence is determined by user code. For example, the platformer tutorial uses this: https://github.com/melonjs/tutorial-platformer/blob/gh-pages/tutorial_step9/js/entities/entities.js#L36-L57 which considers that the left action key always takes precedence (because it is checked first, and it disables checking of the right action key via the else-if clause).
Making the last-key-pressed take precedence will require some extra state tracking, probably in conjunction with the KEYDOWN and KEYUP events.
The part about precedence isn't a bug in the framework. But I haven't been able to verify or reproduce @wheelerau's report about keys registering only after releasing one while another is pressed...
@parasyte would it be useful if I sent you the source code to my project?
@wheelerau For sure! If it's on github, that's good enough.
@wheelerau I don't think I've heard back from you about the code you offered to share for this bug. If you have anything else to add that might also be helpful to investigate this one, I'll take that too! :)
I apologize about that...As per usual my computer crashed and killed the game...Unfortunately i didnt have it connected to github :/ On Jun 26, 2015 11:50 PM, "Jay Oster" [email protected] wrote:
@wheelerau https://github.com/wheelerau I don't think I've heard back from you about the code you offered to share for this bug. If you have anything else to add that might also be helpful to investigate this one, I'll take that too! :)
— Reply to this email directly or view it on GitHub https://github.com/melonjs/melonJS/issues/676#issuecomment-116000106.
Ok, no worries. Closing this one because we cannot reproduce, and need more information.