I am trying to develop a dodge style game with falling enemies that features the ability for the player to 'sprint' while holding down the spacebar.
I have tried to multiply the velocity of the player while space.isdown() is true, but the player disappears once space is pressed.
function update() {
if (gameState.cursors.left.isDown) {
gameState.player.setVelocityX(-160);
} else if (gameState.cursors.right.isDown) {
gameState.player.setVelocityX(160);
} else {
gameState.player.setVelocityX(0);
}
//Sprint Ability
if (gameState.player.velocityx != 0 && gameState.cursors.space.isDown){
gameState.player.setVelocityX(gameState.player.velocityx * 2);
} else {};
}