Jump to content

[Solved] Multiple key.isDown


FlopshotQQ
 Share

Recommended Posts

Somewhat new to Phaser, the game is similar to pong and there's a two player mode.
The problem I'm encountering is that when both directional keys for one paddle are being held down (A&D or LEFT&RIGHT) no more input is being accepted. Leaving the other player unable to move their paddle.
Below is a simplified version of the code.

Any help or information is appreciated :)

 

//something to the effect of

var paddle1Speed = 900;
var paddle1Acceleration = 0;
var paddle1Pressure = 10;
var paddle2Speed = 900;
var paddle2Acceleration = 0;
var paddle2Pressure = 10;
var maxPaddleAcceleration = 300;


function update ()
{
player2ControlListen ();
player2ControlListen ();

}




function player1ControlListen ()
{
    if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
    {
            if (paddle1.body.velocity.x > -paddle1Speed)
            {
                if (paddle1Acceleration > -maxPaddleAcceleration)
                {
                  paddle1Acceleration -= paddle1Pressure;
                }
              paddle1.body.velocity.x += paddle1Acceleration;
            }
    }
    if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
    {
          if (paddle1.body.velocity.x < paddle1Speed)
          {
              if (paddle1Acceleration < maxPaddleAcceleration)
              {
                paddle1Acceleration += paddle1Pressure;
              }
            paddle1.body.velocity.x += paddle1Acceleration;
          }
    }

}

function player2ControlListen ()
{
        if (game.input.keyboard.isDown(Phaser.Keyboard.A))
        {
          if (paddle2.body.velocity.x > -paddle2Speed)
          {
              if (paddle2Acceleration > -maxPaddleAcceleration)
              {
                paddle2Acceleration -= paddle2Pressure;
              }
            paddle2.body.velocity.x += paddle2Acceleration;
          }
        }
        if (game.input.keyboard.isDown(Phaser.Keyboard.D))
        {
          if (paddle2.body.velocity.x < paddle2Speed)
          {
              if (paddle2Acceleration < maxPaddleAcceleration)
              {
                paddle2Acceleration += paddle2Pressure;
              }

          paddle2.body.velocity.x += paddle2Acceleration;
        }
      }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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