crffty Posted January 18, 2017 Share Posted January 18, 2017 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 More sharing options...
erich Posted January 18, 2017 Share Posted January 18, 2017 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 More sharing options...
phreaknation Posted January 18, 2017 Share Posted January 18, 2017 Side note in js. If two functions share the same exact functionality you can go A = B = function () {}; Or B = function () {}; A = B; Link to comment Share on other sites More sharing options...
Recommended Posts