melonJS icon indicating copy to clipboard operation
melonJS copied to clipboard

Multi-Key input registered after key release

Open LazyPlatypus9 opened this issue 11 years ago • 9 comments

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.

LazyPlatypus9 avatar Mar 13 '15 20:03 LazyPlatypus9

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.

jakeabel avatar Mar 13 '15 20:03 jakeabel

@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?

parasyte avatar Mar 13 '15 23:03 parasyte

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.

jakeabel avatar Mar 15 '15 04:03 jakeabel

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 avatar Mar 15 '15 04:03 parasyte

@parasyte would it be useful if I sent you the source code to my project?

LazyPlatypus9 avatar Mar 15 '15 19:03 LazyPlatypus9

@wheelerau For sure! If it's on github, that's good enough.

parasyte avatar Mar 16 '15 00:03 parasyte

@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! :)

parasyte avatar Jun 27 '15 09:06 parasyte

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.

LazyPlatypus9 avatar Jun 27 '15 20:06 LazyPlatypus9

Ok, no worries. Closing this one because we cannot reproduce, and need more information.

parasyte avatar Jun 29 '15 05:06 parasyte