Key Posted November 8, 2017 Share Posted November 8, 2017 Hi ! I'm new with phaser and i'm making a game, I have trouble with the double jump. I checked the others forum but it doesn't work with my game. I tried this and i checked the count of the jumps with an alert, and i see that it doesn't work bu i don't know why. // DOUBLE JUMP if (player.body.touching.down) // if player touch plateform, he gains his double jump { var jump = 2; } if (cursors.up.isDown && jump==2) { player.body.velocity.y = -400; //jump counter -1 jump--; alert(jump); } if (cursors.up.isDown && jump==1 ) { player.body.velocity.y = -400; jump--; alert(jump); } Thanks. Link to comment Share on other sites More sharing options...
samme Posted November 10, 2017 Share Posted November 10, 2017 var jump = 0; update () { // … if (player.body.touching.down) { jump = 2; } if (cursors.up.isDown && jump > 0) { jump--; player.body.velocity.y = -400; } // … } Link to comment Share on other sites More sharing options...
Key Posted November 13, 2017 Author Share Posted November 13, 2017 SOrry, it doesn't work for me. But this work : cursors.up.onDown.add(jumpCheck); if(player.body.touching.down){ jumpCount = 0; } function jumpCheck() { if((jumpCount < 1) && (player.body.touching.down)){ jump1(); // attention, remettre jumpCount à zéro si on touche le sol // if(player.body.touching.down){ // jumpCount = 0; // } } //double jump if((jumpCount < 2) && (!player.body.touching.down)){ jump2(); } } function jump1(){ jumpCount ++; player.body.velocity.y = -450; } function jump2(){ jumpCount ++; player.body.velocity.y = -450; } Link to comment Share on other sites More sharing options...
gauravD Posted November 14, 2017 Share Posted November 14, 2017 @samme's answer should work just fine. Regardless, since jump1() and jump2() are equivalent, why not just use jump()? Link to comment Share on other sites More sharing options...
piotr Posted November 14, 2017 Share Posted November 14, 2017 Game Mechanic Explorer's website has a double jump example in Phaser https://gamemechanicexplorer.com/#platformer-5 Machine-dev 1 Link to comment Share on other sites More sharing options...
Machine-dev Posted November 14, 2017 Share Posted November 14, 2017 I believe the secret is upInputReleased(). Otherwise user cursors.up.isDown will be detected twice (or more), immediately exhausting any saved jumps. Link to comment Share on other sites More sharing options...
samme Posted November 15, 2017 Share Posted November 15, 2017 Think you can use as well: cursors.up.justPressed() Link to comment Share on other sites More sharing options...
Recommended Posts