I am making a javascript game where the player jumps over oncoming cars, but after the first jump every time the player hits the ground they jump again automatically. I believe the problem is because I am resetting the jumping variable to false when it hits the ground yet it is still going through the initial jump() function so it sees it as false and makes it jump again. Is there any way to fix this?
this.isJumping = function(){
var y=player.y;
var jumping;
if (y=area.canvas.height - 200){
player.image.src="man.png";
}
else{
jumping=true;
player.image.src="man2.png";
}
return jumping;
}
(And later in the code)
function jump() {
if (!player.isJumping() && area.frameNo>0) {
player.speedY = -20;
jumping=true;
}
}
jump()
? \$\endgroup\$=
instead of==
? \$\endgroup\$