Key

How to double jump with phaser ?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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;
       
    } 
   
    

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.