class PreloadScene extends Phaser.Scene {
super({ key: "PreloadScene" });
let progressBox = this.add.graphics();
progressBox.fillStyle(0x222222, 0.8);
progressBox.fillRoundedRect(boxX, boxY, boxWidth, boxHeight, boxHeight / 2);
let loadingText = this.add
.text(config.width / 2, config.height / 2, "Chargement", {
let progressBar = this.add.graphics();
this.load.on("progress", (value) => {
let targetWidth = (boxWidth - 10) * value;
currentWidth: targetWidth,
progressBar.fillStyle(0x00ff00, 1);
progressBar.fillRoundedRect(
loadingText.setText("Chargement ✔");
this.load.on("complete", () => {
this.time.delayedCall(1500, () => {
this.cameras.main.fadeOut(1000, 0, 0, 0);
this.cameras.main.on("camerafadeoutcomplete", () => {
this.scene.start("SceneA");
this.load.image("bg", "https://assets.codepen.io/9367036/forest1.jpg");
this.load.image("bg2", "https://assets.codepen.io/9367036/forest3.jpg");
class SceneA extends Phaser.Scene {
super({ key: "SceneA" });
this.cameras.main.fadeIn(500, 0, 0, 0);
let background = this.add.image(0, 0, "bg").setOrigin(0, 0);
background.displayWidth = config.width;
background.displayHeight = config.height;
let playText = this.add.text(400, 300, "Scène B", {
backgroundColor: "#000000",
padding: { x: 20, y: 5 },
playText.setInteractive({ useHandCursor: true });
playText.once("pointerdown", () => {
const fx = this.cameras.main.postFX.addWipe();
onUpdate: (progress) => {
class SceneB extends Phaser.Scene {
super({ key: "SceneB" });
let background = this.add.image(0, 0, "bg2").setOrigin(0, 0);
background.displayWidth = config.width;
background.displayHeight = config.height;
let playText = this.add.text(400, 300, "Scène A", {
backgroundColor: "#ffffff",
padding: { x: 20, y: 5 },
playText.setInteractive({ useHandCursor: true });
playText.once("pointerdown", () => {
const fx = this.cameras.main.postFX.addWipe();
onUpdate: (progress) => {
scene: [PreloadScene, SceneA, SceneB]
const game = new Phaser.Game(config);