Jump to content

How to capture right click using onInputDown on a Phaser.Sprite


Kazrian
 Share

Recommended Posts

Hello,

I'm trying to handle right-click events on the sprites in my game so that I can display context menus, but I can't find a way to tell if the onInputDown event on the sprite was triggered by a right click.  I've tried checking this.game.input.mouse.button, but it always comes up as -1.  I've tried checking the rightButton property on the pointer passed into the onInputDown callback as a parameter, but rightButton comes up as undefined.  How can I do this?  I was expecting a simple way like onInputRightButton, or a parameter passed to the callback that would let me detect the source of the input.

Thanks!

Link to comment
Share on other sites


var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });

function preload() {

    game.load.image('mouse', 'assets/sprites/mouse_jim_sachs.png');

}

function create() {

    game.stage.backgroundColor = '#943021';

    var sprite = game.add.sprite(0, 100, 'mouse');

    sprite.inputEnabled = true;

    sprite.events.onInputDown.add(click, this);

    game.input.mouse.capture = true;

}

function click (sprite, pointer) {

    console.log(pointer.leftButton.isDown);
    console.log(pointer.rightButton.isDown);

}

function render() {

    game.debug.text("Left Button: " + game.input.activePointer.leftButton.isDown, 300, 132);
    game.debug.text("Middle Button: " + game.input.activePointer.middleButton.isDown, 300, 196);
    game.debug.text("Right Button: " + game.input.activePointer.rightButton.isDown, 300, 260);

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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