im trying to make a double jump method for my game the method works but it registers the button presses to fast and just jumps forever
here is the code i have for movement and for double jump i am looking for a way to slow down how fast it registers a button click
1 2 3 4 5 6 7 8 9 10 11 | public void doubleJump() { if (numJumps == 1 ) { vSpeed = -jumpStrength; setImage( new GreenfootImage( "PlayerDouble.png" )); fall(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | public void act() { if (Greenfoot.isKeyDown( "left" )) { moveLeft(); Actor p = this .getOneIntersectingObject(Platforms. class ); if (p != null ) { moveRight(); } } if (Greenfoot.isKeyDown( "right" )) { moveRight(); Actor p = this .getOneIntersectingObject(Platforms. class ); if (p != null ) { moveLeft(); } } if (Greenfoot.isKeyDown( "up" ) && onPlatforms() && numJumps < 2 ) { jump(); numJumps++; } hitSpike(); hitGoal(); if (onPlatforms()) { vSpeed = 0 ; numJumps = 0 ; setImage( new GreenfootImage( "Player.png" )); } else { fall(); } if (Greenfoot.isKeyDown( "up" ) && numJumps < 2 && dbJumped == false ) { doubleJump(); dbJumped = true ; } } |