Hello, I’ve been trying to make a 2 player platformer game (with local control WASD and arrow keys).
and I’ve look at the basic platformer control example on phaser website.
However I came across a little problem when I try to restart the scene.
So what I’m trying to get is, when the players falls out of the map → scene will restart → if player still holds the move input → player keeps moving after scene reset.
However when I hold two input (both player move input / move and jump input) only the last input that is pressed get registered after scene restart.
example:
player 1 move input right(hold) → player 2 move input right(hold) → player fall → scene restart → only player 2 move input got registered.
so even if I’m holding both player move input after the scene restart only one of them is registered as pressed.
is there anyway to get both player input after restart?
Here is the control code snippet:
In Create
player_control = context.input.keyboard.addKeys({
'up': 'up',
'down': 'down',
'left': 'left',
'right': 'right' });
player2_control = context.input.keyboard.addKeys({
'up': Phaser.Input.Keyboard.KeyCodes.W,
'down': Phaser.Input.Keyboard.KeyCodes.S,
'left': Phaser.Input.Keyboard.KeyCodes.A,
'right': Phaser.Input.Keyboard.KeyCodes.D });
In Update
/* Player 1 Control */
if(player_control.left.isDown){
player.body.velocity.x = -moveVelocity;
player.flipX = true;
}
else if(player_control.right.isDown){
player.body.velocity.x = moveVelocity;
player.flipX = false;
}
else{
player.body.velocity.x = 0;
}
/* Player 2 Control */
if(player2_control.left.isDown){
player2.body.velocity.x = -moveVelocity;
player2.flipX = true;
}
else if(player2_control.right.isDown){
player2.body.velocity.x = moveVelocity;
player2.flipX = false;
}
else{
player2.body.velocity.x = 0;
}