Dynamically loading scenes during the main game loop?

I’m teasing out some ideas for “action” moments in a RPG style situation; I have my main “game” scene, but I was thinking that when an event fires, the game scene is paused, another scene is loaded alongside the current game scene - like a popup window - run some automated action (so think like a character casting a spell or something and getting the result), then that dynamic scene is destroyed & the main game scene resumed.

I can see in the examples page you can define multiple scenes in the config:

var config = {
    type: Phaser.WEBGL,
    ...
    scene: [ Background, Demo ]
};

But I’d prefer to do this dynamically, loading sub-scenes when the game needs them, rather than have them always active. That feels more efficient use of assets anyway.

Scenes can be added without being started (activated), and by default, when you use scene: [ a, b … ] only the first scene is started.

Are you sure? I’m fairly sure all scenes loaded in the array are activated. I recall just adding two samples and both animated as expected.

Anyway, thinking more of dynamic locating within a scene, rather than always having one in the background, deactivated til needed. Unless that’s more performant than my suggestion?

It’s like this one: scenes/launch parallel scene.

Your idea is still good, though. You would avoid the work of initializing the scene unnecessarily. It’s done in scenes/add scene from another scene.

1 Like