У Sprite в Phaser 3 не может быть детей, поэтому часть кода sprite.getChildren
меня немного беспокоит. Только у групп есть метод getChildren
.
Самое простое:
const player = this.add.sprite(x, y, texture);
player.setInteractive();
player.on('pointerdown', () => {
console.log('You clicked the player sprite');
});
// Or, if you have a Group full of Sprites:
const sprites = yourGroup.getChildren();
sprites.forEach((child) => {
child.setInteractive();
child.on('pointerdown', () => {
console.log('You clicked a Group sprite');
});
});