Hi everyone,
I’m developing a Phaser 3 game on the AirConsole plattform.
You can actually try it out right now on the AirConsole Simulator if you authenticate with your google account.
The structure of the game is as follows:
class FindItScene extends Phaser.Scene
class MainMenu extends FindItScene
class PauseScreen extends FindItScene
class Guessing extends FindItScene
As I’m reusing a lot of assets in every scene (background, ui elements), this enables me to stay DRY.
Every Scene calls super.preload() and super.create() before doing the elements that are specific to that scene.
Phaser gets initiated as follows:
var config = {
type: Phaser.AUTO,
scale: {
mode: Phaser.Scale.NONE,
parent: 'body',
width: "100%",
height: "100%",
autoCenter: Phaser.Scale.NO_CENTER,
},
scene: [MainMenu, Guessing, TimeScreen, EndOfGame, PauseScreen]
};
// store the game object in the document so its available from everywhere
document.game = new Phaser.Game(config);
AirConsole listens for input from controllers (these are mobile devices) and reports these events.
When these events get triggered, I need to switch scenes from outside of Phaser.
I solved this currently by adding and EventListener to the FindItScene class in its create method:
create(){
// listen for sceneChange by AirConsole
this.events.once("sceneChange", this.handleSceneChange, this);
}
handleSceneChange(args) {
this.scene.start(args.targetScene);
}
So when an AirConsole event comes in that triggers a scene change, I emit the event on the currently active scene:
document.game.scene.getScenes(true)[0].events.emit("sceneChange", {targetScene: targetScene});
Now what i’ve found is that with that approach, there is always a short black screen between each scenes. I could just use a background behind the canvas, but I’m seriously wondering why this would even happen, since, as I understand it, switching scenes just sleeps them, and all the assets should be cached and ready. I’ve also noticed that using launch avoids the black screen, because the old scene just remains behind the new scene, but stacking scenes above each other doesn’t feel correct either.
What is the best approach to having a consistent background image between all Phaser Scenes?