import Phaser from 'phaser';
new Phaser.Game({
scene: {
create,
},
});
let redSquare: Phaser.GameObjects.Rectangle;
let blueSquare: Phaser.GameObjects.Rectangle;
function create(this: Phaser.Scene) {
redSquare = this.add
.rectangle(100, 100, 50, 50, 0xff0000)
.setName('red')
.setInteractive();
blueSquare = this.add
.rectangle(125, 125, 50, 50, 0x0000ff)
.setName('blue')
.setInteractive();
this.input
// .setTopOnly(false) // If you want to check if more than the top most hitbox was clicked
.on(
'pointerdown',
(
pointer: Phaser.Input.Pointer,
objectsClicked: Phaser.GameObjects.GameObject[]
) => {
console.log(objectsClicked);
}
);
}