Jump to content

How to double jump with phaser ?


Key
 Share

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.

Link to comment
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;
       
    } 
   
    
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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