Jump to content

Game Mechanic Explorer question [double jump]


Robooto
 Share

Recommended Posts

Hi,

 

I'm a beginner with Phaser and Javascript and have been learning by playing around with the wonderful Game Mechanic Explorer http://gamemechanicexplorer.com/ (by John Watson @yafd)

 

I noticed in the double jump example http://gamemechanicexplorer.com/#platformer-5 that on mobile (iphone) double jumping wasn't working.

 

 

I'm not going to paste in all the code just the code I think deals with the issue.

  // Set a variable that is true when the player is touching the ground    var onTheGround = this.player.body.touching.down;    if (onTheGround) this.canDoubleJump = true;    if (this.upInputIsActive(5)) {        if (this.canDoubleJump || onTheGround) {            // Jump when the player is touching the ground or they can double jump            this.player.body.velocity.y = this.JUMP_SPEED;            // Disable ability to double jump if the player is jumping in the air            if (!onTheGround) this.canDoubleJump = false;        }    }// This function should return true when the player activates the "jump" control// In this case, either holding the up arrow or tapping or clicking on the center// part of the screen.GameState.prototype.upInputIsActive = function(duration) {    var isActive = false;    isActive = this.input.keyboard.justPressed(Phaser.Keyboard.UP, duration);    isActive |= (this.game.input.activePointer.justPressed(duration + 1000/60) &&        this.game.input.activePointer.x > this.game.width/4 &&        this.game.input.activePointer.x < this.game.width/2 + this.game.width/4);    return isActive;};

From what I gather is that

 if (this.upInputIsActive(5))

 condition is never met on mobile.

 

My question is why doesn't this work on mobile and if someone could point me in the right direction to solve this so it does work on mobile.

 

Thanks!

Link to comment
Share on other sites

I spent some time with this and was able to figure it out.  I created a new jumping method which works just fine on mobile currently adjusting it for variable jumping too.

   // new jumping method    var onTheGround = this.player.body.touching.down;    if (onTheGround) this.jumpAmount = 0;        if ((this.input.keyboard.justPressed(Phaser.Keyboard.UP) || this.game.input.activePointer.justPressed(65)) && this.jumpAmount < 5) {            this.player.body.velocity.y = this.JUMP_SPEED;                        this.jumpAmount++;            console.log(this.jumpAmount);        }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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