Boot Data
Demonstrates how to pass a data object when starting a scene and access it within the init, preload, and create methods for dynamic asset loading and positioning.
800 × 600
class Example extends Phaser.Scene
{
constructor()
{
super({ key: 'test', active: false });
}
init (data)
{
this.png = data.image;
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('mech', 'assets/pics/' + this.png);
}
create (data)
{
this.add.image(data.x, data.y, 'mech');
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
width: 800,
height: 600,
scene: Example
};
const game = new Phaser.Game(config);
game.scene.start('test', { image: 'titan-mech.png', x: 400, y: 300 });