Bates 550 Posted April 18, 2014 Share Posted April 18, 2014 I have a function that uses the following snippet to determine which direction to direct a character in: var right = game.input.keyboard.isDown(Phaser.Keyboard.RIGHT); var left = game.input.keyboard.isDown(Phaser.Keyboard.LEFT); var down = game.input.keyboard.isDown(Phaser.Keyboard.DOWN); var up = game.input.keyboard.isDown(Phaser.Keyboard.UP); console.log("left, right, up, down:", left, ",", right, ",", up, ",", down);The idea is that if the user inputs either both left and right or both up and down then the character should just stop moving since this input doesn't really make sense. However it seems that down and left don't play well together. Some example inputs and console outputs:input: right, up, down; output: left, right, up, down: false, true, true, true // works as expected input: left, up, down; output: left, right, up, down: false, false, true, true // where is left? input: left, right, down; output: left, right, up, down: true, true, false, false // where is down? input: left, right, down (all at the same time); output: left, right, up, down: false, false, false, false // where are all of them?! input: left, right, up; output: left, right, up, down: true, true, true, false // works as expectedWith the exception of 4, all of these keys are (from Phaser's perspective) not pressed at the same time (e.g. when I input right, up, down, it's more akin to right and then right, up, and then right, up, down). I can't get 4 to happen every time, but it's definitely doable. Also, note that 1 and 5 work as expected and do not have both left and down, which leads me to believe that the problem exists when both left and down are in the same input. This is not exactly game breaking, but I am unsure if I am misunderstanding something or if this is a bug in the keyboard input system. You can check out the full code here: https://github.com/Bates550/breezy_field/blob/068bee9f73e46151bf6092cf5d08f449654c19b0/js/game.js#L150 The snippet is from kb_input() on line 150 and seems like it should be the only relevant part of the code to this discussion, but maybe I'm missing something. Link to comment Share on other sites More sharing options...
rich Posted April 20, 2014 Share Posted April 20, 2014 Hmm this topic comes up quite often, I think I had better add it to the docs. But basically the issue is key ghosting, see here: http://www.html5gamedevs.com/topic/4876-impossible-to-use-more-than-2-keyboard-input-buttons-at-the-same-time/ Link to comment Share on other sites More sharing options...
Bates 550 Posted April 24, 2014 Author Share Posted April 24, 2014 Oh, I see. I guess I didn't look hard enough in the forums. Thanks for the reply! Link to comment Share on other sites More sharing options...
Recommended Posts