I have a platforming game, written in javascript with the Phaser.js framework, where my character collects objects. I thought trying to collect all objects in the least amount of jumps would be interesting, so I tried to implement a jump counter. Relevant pieces of code:
var jumpCount = 0;
var jumpText;
function create (){
jumpText = this.add.text(16, 48, 'Jumps Used: 0', {fontsize: '32px', fill: '#000'});
}
function update (jumpCount){
if (cursors.space.isDown && player.body.touching.down){
player.setVelocityY(-630);
jumpCount++;
jumpText.setText('Jumps Used: ' + jumpCount);
}
}
This is displaying the counter and incrementing it sort of correctly, but it seems to count the amount of time that the spacebar is held down and is leading to jump counts that are floats well into the thousands.
Is there a more reasonable way to handle counting the number of times a player has manually jumped?
Thanks!