Hi everyone,
While trying some stuff, I found out that registry doesn’t work when you start scene later on.
So here is an example code about it. Just try this one on labs.
On the link you can see it’s working when you add scenes as active: true
but it doesn’t work when i use it like below.
So any ideas?
var SceneA = new Phaser.Class({
Extends: Phaser.Scene,
initialize: function SceneA() {
Phaser.Scene.call(this, { key: 'SceneA' });
this.score = 0;
},
create: function() {
this.scene.start('SceneB');
this.registry.set('score', this.score);
this.time.addEvent({
delay: 500,
callback: this.onEvent,
callbackScope: this,
loop: true,
});
},
onEvent: function() {
this.score++;
this.registry.set('score', this.score);
},
});
var SceneB = new Phaser.Class({
Extends: Phaser.Scene,
initialize: function SceneB() {
Phaser.Scene.call(this, { key: 'SceneB' });
this.text;
},
create: function() {
this.text = this.add.text(100, 100, 'Monitoring Registry');
this.registry.events.on('changedata', this.updateScore, this);
},
updateScore: function(parent, key, data) {
this.text.setText('Score: ' + data);
},
});
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#2d2d2d',
parent: 'phaser-example',
//scene: [SceneA, SceneB]
};
const game = new Phaser.Game(config);
game.scene.add('SceneA', SceneA, true);
game.scene.add('SceneB', SceneB);
I also opened a github issue on here.