Add Scene From Another Scene
Demonstrates how to dynamically add a new Scene to the Scene Manager and start it immediately while passing custom data to its create method.
800 × 600
class MyScene extends Phaser.Scene {
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('face', 'assets/pics/bw-face.png');
}
create (data)
{
this.face = this.add.image(data.x, data.y, 'face');
}
}
class BootScene extends Phaser.Scene {
create ()
{
this.add.text(0, 0, 'Click to add new Scene');
this.input.once('pointerdown', function () {
this.scene.add('myScene', MyScene, true, { x: 400, y: 300 });
}, this);
}
}
var config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
width: 800,
height: 600,
scene: BootScene
};
var game = new Phaser.Game(config);