Hey guys so this is what I am currently doing for my main player control:
Input.define('MOVEMENT', Key.W, Key.A, Key.S, Key.D);
//player controls
if ( Input.check(Key.A) && !Input.check(Key.D) && !Input.check(Key.S) && !Input.check(Key.W))
{
xSpeed -= power;
pressed = true;
playerSprite.play("left");
direction = 1;
}
if (Input.check(Key.D) && !Input.check(Key.A) && !Input.check(Key.S) && !Input.check(Key.W))
{
xSpeed += power;
pressed = true;
playerSprite.play("right");
direction = 2;
}
if (Input.check(Key.W) && !Input.check(Key.S) && !Input.check(Key.A) && !Input.check(Key.D))
{
ySpeed -= power;
pressed = true;
playerSprite.play("up");
direction = 3;
}
if (Input.check(Key.S) && !Input.check(Key.W) && !Input.check(Key.A) && !Input.check(Key.D))
{
ySpeed += power;
pressed = true;
playerSprite.play("down");
direction = 4;
}
//end of control code
if (Input.pressed('MOVEMENT') || (Input.released('MOVEMENT') && pressed))
{
playSound();
}
Basically all of the added stuff in each Input.check is making sure multiple keys are not being pressed to avoid the player from traveling diagonally. I would however like to be able to have the play say for example, press left, so the player is moving to the left, WHILE they are moving left for example, they press the up key, however since the left key was pressed first they continue to move left, HOWEVER when they release the left key and they are still pressing the up key, they will now travel up.
The way I have it now is great because I don’t want the player to move diagonally, however the player must take their finger off of a key before they can press another. I have gotten used to it, but the few friends I had test my game complained about this right off the bat.
What do you guys think?
Thank you!