Hi all,
I have the 'Play'
scene passing the score to the 'Ending'
scene. In the 'Ending'
scene players should be able to click on a button to go to back to the 'Title'
scene to play again.
I’m using events to pass the score between scenes. The scene plays correctly, data is passed but this somehow interferes with button events: the 'Play'
scene plays instead of the 'Title'
scene.
I’ve tried to not use events and the restartButton
triggers 'Title'
correctly but I then run into other issues like proper scene initialisation and passing the data.
Is there a way to modify EventsCenter or the script to not break button events?
The main game play scene
export default class Play extends Phaser.Scene {
constructor() {
super("Play");
}
create() {
this.score = 0;
//add the end scene and hide it
this.endingScene = this.scene.run('Ending');
this.scene.sleep('Ending');
}
//... all the gameplay code
ending() {
EventsCenter.emit('startEnding', this.score);
}
The ending scene
export default class Ending extends Phaser.Scene {
constructor(settings) { super('Ending'); }
create() {
var restartButton = new Button();
EventsCenter.on('startEnding', this.startEnding, this);`
restartButton.on('pointerdown',() => { this.scene.start('Title'); }); //tried with 'this' and without it
}
showEnding() {
this.scene.wake(this);
}
EventsCenter.js I’ve been using this script to pass data between scenes successfully
const eventsCenter = new Phaser.Events.EventEmitter()
export default eventsCenter;