Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registry doesn't work when scenes start later #5266

Closed
halilcakar opened this issue Aug 13, 2020 · 2 comments
Closed

Registry doesn't work when scenes start later #5266

halilcakar opened this issue Aug 13, 2020 · 2 comments

Comments

@halilcakar
Copy link
Contributor

Version

  • Phaser Version: v3.50.0-beta.1-FB
  • Operating system: Windows 10 Pro
  • Browser: Chrome, Mozilla,

Description

So on the example on Scenes/Registry Data Exchange we have the registry that we can send data through scenes. The way i use to add scenes is following:

game.scene.add('PreloadScene', PreloadScene, true);
game.scene.add('PlayScene', PlayScene);

So in my example code i've removed active: true from scenes and started SceneB from SceneA. When we use scenes like this, registry and events doesn't work proparly.

Example Test Code

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);
@photonstorm
Copy link
Collaborator

This issue has been mentioned on Phaser. There might be relevant details there:

https://phaser.discourse.group/t/registry-doesnt-work-when-scenes-start-later/7172/1

@halilcakar
Copy link
Contributor Author

Hi @photonstorm yea i've also created that and ask about community ideas =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants