Jump to content

keyboard.isDown bug?


ZaCkOX
 Share

Recommended Posts

I seen to have hit a major problem... I believe it is a phaser issue but not really sure. If I hold down several keys, like Q and Z, then try to press W, F, H, etc. randomly some keys seem to not be triggered.

 

update: function ()
{
    //Check player movements
    this.CheckPlayersControls();
},

 

CheckPlayersControls: function ()
{
    //Check player 1 movement
    this.CheckPlayersInput(this.spritePlayer1,
                           this.Cursors.left.isDown,
                           this.Cursors.right.isDown,
                           this.Cursors.up.isDown,
                           this.Cursors.down.isDown,
                           this.input.keyboard.isDown(Phaser.Keyboard.Z),
                           this.input.keyboard.isDown(Phaser.Keyboard.X),
                           0);
    //Check player 2 movement
    this.CheckPlayersInput(this.spritePlayer2,
                           this.input.keyboard.isDown(Phaser.Keyboard.A),
                           this.input.keyboard.isDown(Phaser.Keyboard.D),
                           this.input.keyboard.isDown(Phaser.Keyboard.W),
                           this.input.keyboard.isDown(Phaser.Keyboard.S),
                           this.input.keyboard.isDown(Phaser.Keyboard.Q),
                           this.input.keyboard.isDown(Phaser.Keyboard.E),
                           1);
    //Check player 3 movement
    this.CheckPlayersInput(this.spritePlayer3,
                           this.input.keyboard.isDown(Phaser.Keyboard.F),
                           this.input.keyboard.isDown(Phaser.Keyboard.H),
                           this.input.keyboard.isDown(Phaser.Keyboard.T),
                           this.input.keyboard.isDown(Phaser.Keyboard.G),
                           this.input.keyboard.isDown(Phaser.Keyboard.R),
                           this.input.keyboard.isDown(Phaser.Keyboard.Y),
                           2);
    //Check player 4 movement
    this.CheckPlayersInput(this.spritePlayer4,
                           this.input.keyboard.isDown(Phaser.Keyboard.J),
                           this.input.keyboard.isDown(Phaser.Keyboard.L),
                           this.input.keyboard.isDown(Phaser.Keyboard.I),
                           this.input.keyboard.isDown(Phaser.Keyboard.K),
                           this.input.keyboard.isDown(Phaser.Keyboard.U),
                           this.input.keyboard.isDown(Phaser.Keyboard.O),
                           3);
},

 

CheckPlayersInput: function (spritePlayerNumber,keyLeft,keyRight,keyUp,keyDown,keyShoot1,keyShoot2,intPlayerIndex)
{
    //Stops player when not moving anymore
    spritePlayerNumber.body.velocity.x = 0; spritePlayerNumber.body.velocity.y = 0;
    //Movement left or right
    switch (true)
    {
      case keyLeft:
      {
        spritePlayerNumber.body.velocity.x = -spritePlayerNumber.speed;
        break;
      }
      case keyRight:
      {
        spritePlayerNumber.body.velocity.x = spritePlayerNumber.speed;
        break;
      }
    }
    //Movement up or down
    switch (true)
    {
      case keyUp:
      {
        spritePlayerNumber.body.velocity.y = -spritePlayerNumber.speed;
        break;
      }
      case keyDown:
      {
        spritePlayerNumber.body.velocity.y = spritePlayerNumber.speed;
        break;
      }
    }
    //Shooting 1
    if (keyShoot1)
    {
      //this.fire(spritePlayerNumber, intPlayerIndex); NOT USED YET BECAUSE OF THIS PROBLEM
    }
    //Shooting 2
    if (keyShoot2)
    {
      //this.beam(spritePlayerNumber, intPlayerIndex); NOT USED YET BECAUSE OF THIS PROBLEM
    }

},

 

Makes no sense to me, it is a simple sub... I can move the players individually no problem, issues occur when holding down several keys. I tried console.log and it seems the input returns false even if certain keys are held down.

Link to comment
Share on other sites

/**

* The Keyboard class monitors keyboard input and dispatches keyboard events.

*

* _Be aware_ that many keyboards are unable to process certain combinations of keys due to hardware

* limitations known as ghosting. Full details here:

*

* @class Phaser.Keyboard

* @constructor

* @param {Phaser.Game} game - A reference to the currently running game.

*/

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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