This site requires JavaScript, please enable it in your browser!
Greenfoot back
-nic-
-nic- wrote ...

2013/3/12

Holding down a key

-nic- -nic-

2013/3/12

#
I have code in which when you press the spacebar you jump, yet if you hold the spacebar down the actor just floats upwards
if(Greenfoot.isKeyDown("space")&&!canSee(0,-2)){if(jump==true){Y=-1;jump=false;}else{jump=true;}}else if(canSee(0,2)){Y=0;}else{Y=0.5;}
then this i called to move the player
setLocation(getX()+X,getY()+Y);
-nic- -nic-

2013/3/12

#
the canSee method is to test to see if there is a object above or below the jumping object
Game/maniac Game/maniac

2013/3/12

#
Do:
if(Greenfoot.isKeyDown("space")&&!canSee(0,-2)&&canSee(0,2)){if(jump==true){Y=-1;jump=false;}else{jump=true;}}else if(canSee(0,2)){Y=0;}else{Y=0.5;}  
Hawx_ Hawx_

2013/3/13

#
you could also use the getKey method
-nic- -nic-

2013/3/13

#
Thanks Game/maniac that worked :)
Game/maniac Game/maniac

2013/3/13

#
Your welcome
You need to login to post a reply.