Detecting when game is blured (paused)

Hi !
I’m trying to figure out how to detect when my phaser game losses focus and get paused…
I’d like to catch the event in order to pause some external music (audio element) at the same moment.

I get how to pause the game : game.paused = true;
But I don’t find any way to catch the onblur event of the game.
I tried to use the scene event but does’nt trigger :

 this.events.on('pause', function () {
            console.log('Play is paused');
            // game.sounds.pauseMusic();
        });

Any help ?
thanks !

Listen for BLUR, FOCUS, HIDDEN, or VISIBLE on this.game.events.

1 Like