Jump to content

on tap


crffty
 Share

Recommended Posts

I have a sprite jumping if the spacebar is pushed but i also want the same to happen on a mobile if the screen is tapped

this.game.input.keyboard.addKeyCapture([Phaser.Keyboard.SPACEBAR]);

cursors = this.input.keyboard.createCursorKeys();

this.jumpButton = this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR) || this.input.onTap.add(onTap, this);

 what am i missing?

Link to comment
Share on other sites

you could use :

this.spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); // spacebar

this.actionButton = this.add.button(this.game.width - 200, this.game.height - 200, 'actionButton');      // show a jump buttn on screen

this.actionButton.events.onInputDown.add(function(){
           this.player.customParams.mustJump = true;
        }, this);

this.actionButton.events.onInputUp.add(function(){
          this.player.customParams.mustJump = false;
        }, this);

and in the update function :

  if((this.spaceKey.isDown || this.player.customParams.mustJump) && this.player.body.touching.down) {
       //put your jump info here
       }

Eric

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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