Hello, I am trying to implement a couple of scenes in my game in order to understand them, what I am trying to do is navigate from my first scene MainMenu to a second EntryLevel when the user clicks on a play button, I have tried this which does not work:
class MainMenu extends Phaser.Scene {
constructor() {
super('bootGame')
}
preload() {
this.load.image('menuBackground', 'assets/world/menubackground.png');
this.load.image('play_button', 'assets/world/play_button.png');
this.load.audio('menu_music', 'assets/music/menu_music.mp3');
}
create() {
this.add.image(400, 300, 'menuBackground');
var playButton = this.add.image(this.game.renderer.width / 2, this.game.renderer.height / 3, 'play_button').setDepth(1);
playButton.setInteractive();
playButton.on('poninterdown', function () {
this.scene.start('entryLevel')
}, this);
this.sound.play('menu_music', {
loop: true
});
}
}
And I also tried this that at least hooks on the click event but when I click the button I get this error: this.scene.start is not a function, here is the code:
class MainMenu extends Phaser.Scene {
constructor() {
super('bootGame')
}
preload() {
this.load.image('menuBackground', 'assets/world/menubackground.png');
this.load.image('play_button', 'assets/world/play_button.png');
this.load.audio('menu_music', 'assets/music/menu_music.mp3');
}
onObjectClicked() {
this.scene.start('entryLevel')
}
create() {
this.add.image(400, 300, 'menuBackground');
var playButton = this.add.image(this.game.renderer.width / 2, this.game.renderer.height / 3, 'play_button').setDepth(1);
playButton.setInteractive();
this.input.on('gameobjectdown', this.onObjectClicked);
this.sound.play('menu_music', {
loop: true
});
}
}
How can I change the scene when I click the play button correctly?