Hi,
this is related to my former post, but a completely different problem now, I hope it is ok to open a new thread. I have an experimental selfmade usb-controller for a kiosk application which is communicating to phaser in the following architecture.
All Scenes are standard Phaser 3 Scenes, including the ControllerScene. The MainScene launches and stops (on scene change) 3 more scenes,
I am using the registry as a convenient way to communicate between the Scenes, scince it is not too much input coming from the controller. The registry stores the controller state received from the Controller API, which is basically used for triggering the scene change between the main scene and the ErrorScene. And to update three values every 300ms based on the input values coming from the controller.
This all works well until I trigger a scene change through the registry by changing the data in the State key in the registry . As soon as I change the scene, e.g. when I detach (->ErrorScene) and re-attach (->MainScene) the controller the registry fires one time more with every change of the scene. So after 5 scene changes it fires 6 times, which I noticed because the scene intro sound played 6 times with just some miliseconds offset,
I change the scenes as follows:
this.cameras.main.fadeOut(300, 0, 0, 0);
this.cameras.main.once(Phaser.Cameras.Scene2D.Events.FADE_OUT_COMPLETE, ()=>{
this.scene.stop('ErrorScene');
this.scene.start('MainScene');
});
and vice versa. I guess I have a misundertanding of the registry. As shown in the image, each related scene listens either to the registry change of the state or a value. Scince all scenes with the listerner listen to the regsitry , I suspect this to be the reason. I filter the data by the key in the according data function, which also works well.
updateData(parent: any , key: any, data: any) {
if(key === 'controllerState') {
if(data === 'attached') {
this.leave();
}
}
}
What am I missing or what can be the reason? What happens to the listeners when I start and stop the scenes? Any help appreciated!