phaser 3 buttons code example

Example 1: phaser 3 add button

// works with either text or an image/sprite
// const button = this.add.text( 100, 100, 'Click me!', { fill: '0f0' })
const button = this.add.sprite( 100, 100, 'button')
	.setInteractive()
	.on('pointerdown', () => button.setScale( 1.1 ))
	.on('pointerup', () => button.setScale( 1 ));

Example 2: phaser3 button not working

create () {
    this.startBtn = this.add.sprite(100, 100, 'startBtn').setInteractive();

    this.startBtn.on('pointerover', function (event) { /* Do something when the mouse enters */ });
    this.startBtn.on('pointerout', function (event) { /* Do something when the mouse exits. */ });
    this.startBtn.on('pointerdown', startGame); // Start game on click.
}