Add menu background video and music to IntroScene with audio management
This commit is contained in:
parent
4bcbfbd9c9
commit
c66b05e5e0
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -356,6 +356,7 @@ export class GameScene extends Phaser.Scene {
|
|||
}
|
||||
|
||||
_onGameOver() {
|
||||
this._bgMusic?.stop();
|
||||
this.scene.launch('GameOverScene');
|
||||
this.scene.pause();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,22 @@ export class IntroScene extends Phaser.Scene {
|
|||
super({ key: 'IntroScene' });
|
||||
}
|
||||
|
||||
preload() {
|
||||
this.load.video('menu-bg', './assets/video/menu.mp4');
|
||||
this.load.audio('music-menu', './assets/music/menuBackground.mp3');
|
||||
}
|
||||
|
||||
create() {
|
||||
const W = this.scale.width;
|
||||
const H = this.scale.height;
|
||||
|
||||
this.add.rectangle(W / 2, H / 2, W, H, 0x000000);
|
||||
// Background video sized exactly to the canvas, looping
|
||||
const video = this.add.video(W / 2, H / 2, 'menu-bg').setDepth(0);
|
||||
//video.setDisplaySize(W, H);
|
||||
video.play(true); // true = loop
|
||||
|
||||
// Dark overlay so text stays readable
|
||||
this.add.rectangle(W / 2, H / 2, W, H, 0x000000, 0.45).setDepth(1);
|
||||
|
||||
this.add.text(W / 2, H / 2 - 100, 'OVERRUN', {
|
||||
fontFamily: 'FutureImperfect',
|
||||
|
|
@ -15,17 +26,17 @@ export class IntroScene extends Phaser.Scene {
|
|||
fill: '#00ccff',
|
||||
stroke: '#003366',
|
||||
strokeThickness: 6,
|
||||
}).setOrigin(0.5);
|
||||
}).setOrigin(0.5).setDepth(2);
|
||||
|
||||
this.add.text(W / 2, H / 2, 'Survive the waves. Choose your power.', {
|
||||
fontSize: '20px',
|
||||
fill: '#aaaaaa',
|
||||
}).setOrigin(0.5);
|
||||
}).setOrigin(0.5).setDepth(2);
|
||||
|
||||
const prompt = this.add.text(W / 2, H / 2 + 80, 'Press ENTER or click to start', {
|
||||
fontSize: '22px',
|
||||
fill: '#ffffff',
|
||||
}).setOrigin(0.5);
|
||||
}).setOrigin(0.5).setDepth(2);
|
||||
|
||||
// Blink the prompt
|
||||
this.tweens.add({
|
||||
|
|
@ -40,13 +51,17 @@ export class IntroScene extends Phaser.Scene {
|
|||
this.add.text(W / 2, H - 60, 'WASD — Move Mouse — Aim Left Click — Fire', {
|
||||
fontSize: '14px',
|
||||
fill: '#666666',
|
||||
}).setOrigin(0.5);
|
||||
}).setOrigin(0.5).setDepth(2);
|
||||
|
||||
this._menuMusic = this.sound.add('music-menu', { loop: true, volume: 1.0 });
|
||||
this._menuMusic.play();
|
||||
|
||||
this.input.keyboard.once('keydown-ENTER', () => this._start());
|
||||
this.input.once('pointerdown', () => this._start());
|
||||
}
|
||||
|
||||
_start() {
|
||||
this._menuMusic.stop();
|
||||
this.scene.start('GameScene');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue