Below is my code. All I am trying to do is, when I press the SPACE key, the character doesn’t keep going up. The spacebar is acting like a turbo button. If I press the space bar once, the character jumps, if I hold down the space bar, the character continues to keep going up. How to I make this so when the player presses the space or holds down the space, you will only execute a jump?
class Hero extends MovieClip
{
var velocity;
var isJumping;
var jumpSpeed;
var startY;
function onLoad()
{
velocity = 10;
isJumping = false;
jumpSpeed = 0;
startY = _y;
}
function onEnterFrame()
{
if(Key.isDown(Key.RIGHT))
{
this.gotoAndStop(2);
_x = _x + velocity;
}
else if(Key.isDown(Key.LEFT))
{
this.gotoAndStop(3);
_x = _x -+ velocity;
}
else
{
this.gotoAndStop(1);
}
if(isJumping)
{
_y += jumpSpeed;
jumpSpeed += 1;
if(_y >+ startY)
{
_y = startY;
isJumping = false;
}
}
if(Key.isDown(Key.SPACE))
{
isJumping = true;
jumpSpeed = -5;
}
}
}