Sound problem on changing scenes

Hello,

I have two scenes that each play a short intro sound in its create() method with this.sound.play('sndOne'); in the first scene and this.sound.play('sndTwo'); in the second. I am switching between the scenes with the this.scene.start('SecondScene'); and this.scene.start('FirstScene');

The more often I switch between the scenes the more often the according sound of the scene plays more or less simultaniously with a delay in ms as if it is launched several times in the create() method. When I switch three times between the scenes, it seems that it plays three times simultanously and five times if I switch five times etc.

What can be the reason or what am I missing conceptually?

Many thanks for any help.
C.

:wave:

Sound playback is global, so you should either stop the sound when leaving the scene or prevent adding/playing the same sound when starting the scene.

Many thanks @samme . I tried this but it doesn´t seem to be the problem. It seems that the problem is that the scene change is called out of my on registry update method, which I did not mention, because I thaught it was irrelevant, sorry. But now I guess it is the cause of the problem.

I write the game (actually a small kiosk app) in electron with typescript and use an experimental USB Controller and its API sends an attached and detached event when its attched/detached to/from the USB port. I use the event to set an according state in the registry. When it detaches a pause scene is started and when it re-attaches it starts the main scene again.

To do so I use the registry in each scene as follows and I wonder if both scenes react to the change and I create some kind of loop?

    this.registry.events.on('changedata', this.updateData, this);

Main Scene

updateData(parent: any , key: any, data: any) {
    if(key === 'controllerState') {
      if(data === 'detached') {
        this.leave(); // fades out the camera and starts the other scene
      }
    }
  }

Pause Scene

updateData(parent: any , key: any, data: any) {
    if(key === 'controllerState') {
      if(data === 'attached') {
        this.leave();
      }
    }
  }

When I change the same scene the standard way, e.g.

this.input.keyboard.on('keydown-Q', () => this.leave());

The sounds play as expected.

I know this is very specific but hopefully not too confusing. :slight_smile:

1 Like

hm, i found that sound keeps playing when i load another set of data into the div containing the phaser field too (jquery) but i dont know what background process to look for and how to reach it

It is, as I suspected, the registry that fires several times after changing between the scenes and the problem is not related to the sound. Solved in my other post.