Jump to content

keyboard.isDown incorrect for input of down, left, and right

Bates 550

Recommended Posts

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:

  1. input: right, up, down; output: left, right, up, down: false, true, true, true // works as expected
  2. input: left, up, down; output: left, right, up, down: false, false, true, true // where is left?
  3. input: left, right, down; output: left, right, up, down: true, true, false, false // where is down?
  4. input: left, right, down (all at the same time); output: left, right, up, down: false, false, false, false // where are all of them?!
  5. input: left, right, up; output: left, right, up, down: true, true, true, false // works as expected

With 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


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...