View Full Version : [AS2] Make Character Jump only Once - not multiple times

03-16-2009, 02:52 PM
I'm working on a small platform game to get some AS experience.

I have my character moving everywhere I want to with one small exception - when I Jump, the character jumps, but if you don't release the jump key, he keeps jumping over and over again. I would like him to only jump one time, then not jump again unless you release the jump key and press it again.

player.vx=0; //Velocity X
player.vy=0; //Velocity y
player.power=.2; //Power used to increase the vx for moving.
player.jump=-10; //What vy will be set to when jumping.
player.jumping=false; //If the player is jumping

if(Key.isDown(Key.UP)&& !player.jumping){ //if the up arrow key is down and the player is not jumping
player.vy+=player.jump; //add the value of jump to players vy
player._y+=player.jump; //move the players y to prevent it being caught by the collisions.
player.jumping=true; //The player is now jumping


03-16-2009, 04:16 PM
use a boolean to check whether the jump key has been released or not.
Pseudo code
if(<condition> && can_jump==true )
if(onground && !jump_key && can_jump==false)