What is the proper syntax for using .isVisible()?

There are two ways it seems to check if the scene is visible. However, I can’t find any examples of syntax to get it to work. Everything I try errors or returns null. How can I use this method?

None of these work:

console.log(game.scenes.isVisible());
console.log(game.scene.isVisible());
console.log(game.Scenes.isVisible());
console.log(game.scenes.isVisible("default"));

Method 1) https://photonstorm.github.io/phaser3-docs/Phaser.Scenes.ScenePlugin.html

Method 2) https://photonstorm.github.io/phaser3-docs/Phaser.Scenes.Systems.html

I am trying to figure out the answer to this thread with an if statement so I can ignore animations and make a pause screen when things are tabbed out.

You have to pass the key of the scene to this.scene.isVisible()

class MainScene extends Phaser.Scene {
  constructor() {
    super({ key: 'MainScene' }) // the scene's key
  }

  create() {
    console.log(this.scene.systems.isVisible()) // checks if the current scene is visible | returns true
    console.log(this.scene.isVisible('MainScene')) // checks if the 'MainScene' is visible | returns true
    console.log(this.scene.isVisible('PreloadScene')) // checks if the 'PreloadScene' is visible | returns false
}

1 Like

I almost had it with console.log(game.scenes.isVisible("default"));. It’s confusing how the documentation has scene and scenes, but uses only scene. Just a simple syntax is all I needed!

Now we will see if this can solve my other issues. :slight_smile: The more I use HTML5, the less I understand why Steve Jobs waged war on Flash to promote an inferior user experience that won’t match it for at least decade. Don’t get me wrong, I’m having fun, but Flash stopped the googles and apples of the world from fragmenting the UX. Phaser works great, it’s a step in the right direction for sure, but it’s damn frustrating so far. :confused:

I have not use flash a lot. But I LOVE phaser :smiley:

Do not forget to check the :ballot_box_with_check: on the post that solved your question.

Use the scene plugin. key is optional.

this.scene.isVisible()

this.scene.isSleeping()
2 Likes

In Phaser 3 you should never do anything via game. The moment you reach for that property, stop, slap yourself, and realise you’re going about it the opposite way that I intended when I built it.

Everything is handled via the Scene itself, in this case, it’s the ScenePlugin that can tell you if a Scene is visible or not. But if you want to check the Scene you’re actually in, then it’s just this.sys.isVisible(), nothing else needed.

4 Likes

This should be a sticky probably in the docs and examples. I can’t remember seeing that anywhere. Of course I only have one scene for what I’m doing here, so the next project I want to improve, not get stuck even more. :slight_smile: