eloguvnah Posted January 3, 2014 Share Posted January 3, 2014 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 More sharing options...
@99golems Posted January 3, 2014 Share Posted January 3, 2014 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 ++; }} DWboutin and RKueny 2 Link to comment Share on other sites More sharing options...
eloguvnah Posted January 3, 2014 Author Share Posted January 3, 2014 Great! Thanks so much! Link to comment Share on other sites More sharing options...
Recommended Posts