[phaser3] 마우스 클릭 좌표와 충돌하는 오브젝트 알아내기

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);
      }
    );
}

Subscribe to X세대 신입사원

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe
774-86-01972 cinnabar.3d@gmail.com