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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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