Jump to content

The double jump


eloguvnah
 Share

Recommended Posts

Hey guys, 

 

Hopefully this will be a quick answer. I'm trying to get a double jump thing going on and this is how I implemented it but it's not working

 

// jumpingif ( player.body.touching.down ) {jumpTimes = 0;}if ( game.input.keyboard.isDown(Phaser.Keyboard.UP) && jumpTimes < 2) {player.body.velocity.y = -350;jumpTimes++;}
 
Link to comment
Share on other sites

i'm going to guess it's because game.input.keyboard.isDown checks to see if the key is pressed and returns true each frame if the key is pressed down. The result is each time you "press" the up key it actually fires a bunch of times in the time it takes for your finger to press it and release.

 

If you want the event to fire only once when a key is pressed, I suggest you do the following code:

this.jumpCount = 0;this.jumpkey = game.input.keyboard.addKey(Phaser.Keyboard.UP);this.jumpkey.onDown.add(jumpCheck, this); //tells phaser to fire jumpCheck() ONCE per onDown event.jumpCheck = function(){   if (player.jumpCount < 2){      player.jump();      player.jumpCount ++;   }}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...