Pointer Button Status
Demonstrates how to track pointer coordinates and check the status of specific mouse buttons, including detection of the right mouse button.
800 × 600
class Example extends Phaser.Scene
{
text;
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('mouse', 'assets/sprites/mouse_jim_sachs.png');
}
create ()
{
this.add.sprite(0, 600, 'mouse').setOrigin(0, 1);
this.text = this.add.text(10, 10, '', { fill: '#00ff00' });
}
update ()
{
const pointer = this.input.activePointer;
this.text.setText([
`x: ${pointer.worldX}`,
`y: ${pointer.worldY}`,
`isDown: ${pointer.isDown}`,
`rightButtonDown: ${pointer.rightButtonDown()}`
]);
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
width: 800,
height: 600,
disableContextMenu: true,
scene: Example
};
const game = new Phaser.Game(config);