I’m really not sure how to pinpoint the problem here. In my game, I have the player character moving with the WASD keys and performing actions with J, K, U, I, N, and M. For some reason, whenever the player is holding down J to shoot and attempts to move up and left by holding down W and A, this will not work. Whichever direction key was pressed first will go into effect, but the second won’t turn it into diagonal movement. For example if the player is shooting by holding down J, then holds A to move left, this will work fine. If the player then presses W to go up and to the left while shooting, the player will continue traveling to the left and won’t go up at all. The strange part of the problem is that the player can go up and left while not performing an action, or while performing the actions mapped to other keys that aren’t J. Even stranger, if I use my key mapping screen to change the basic shooting action to another key, this will then work. If I map a different action to J, this will then fail to work as in the original case despite working with a different key set.
I’ve done everything I can to verify that this isn’t an issue with my code. I’ve changed up which keys I use for both directional movement and actions, and I’ve used the debugger to ensure that all of the data other than the per-frame keydown information is as it should be. No matter what I do, it seems like for whatever reason Phaser isn’t recognizing an A/W keypress if J and W/A are held down. Every other combination I’ve tried seems to work just fine. I’m really at a loss for what’s going on here. For now the solution is to simply change my default control scheme and everything works fine, but I’d really love to figure out what is going on here. I’ve included relevant code snippets and am using a minimized version of Phaser downloaded today.
//Control.js
Movement()
{
return {x: 0, y: 0};
}
//Input.js, inherits Control.js
Movement()
{
var velocity = super.Movement();
if(this.Left())
{
velocity.x -= 1;
}
if(this.Right())
{
velocity.x += 1;
}
if(this.Up())
{
velocity.y -= 1;
}
if(this.Down())
{
velocity.y += 1;
}
return velocity;
}
Left()
{
return this.keys.left.isDown;
}
Right()
{
return this.keys.right.isDown;
}
Up()
{
return this.keys.up.isDown;
}
Down()
{
return this.keys.down.isDown;
}
//Player.js
MovementUpdate()
{
this.setVelocityX(0);
this.setVelocityY(0);
var velocity = this.control.Movement();
this.setVelocityX(velocity.x * this.horizontalVelocity);
this.setVelocityY(velocity.y * this.verticalVelocity);
}