| import Phaser from 'phaser'; |
| import { MAX_LEVEL } from '../constants.js'; |
|
|
| export default class PreloadScene extends Phaser.Scene { |
| constructor() { |
| super({ key: 'PreloadScene' }); |
| } |
|
|
| preload() { |
| |
| this.load.font('retro', 'assets/fonts/font.otf', 'opentype'); |
|
|
| |
| const loadingText = this.add.text(128, 112, 'LOADING...', { |
| fontFamily: 'monospace', |
| fontSize: '8px', |
| color: '#ffffff' |
| }).setOrigin(0.5); |
|
|
| |
| this.load.image('blocks-spritesheet', 'assets/blocks.png'); |
|
|
| |
| for (let i = 1; i <= MAX_LEVEL; i++) { |
| this.load.image(`backdrop-${i}`, `assets/backdrops/level-${i}/backdrop.png`); |
| } |
|
|
| |
| for (let i = 1; i <= MAX_LEVEL; i++) { |
| this.load.audio(`music-${i}`, `assets/music/level-${i}/track.mp3`); |
| } |
|
|
| |
| this.load.on('progress', (value) => { |
| loadingText.setText(`LOADING... ${Math.floor(value * 100)}%`); |
| }); |
|
|
| this.load.on('complete', () => { |
| |
| loadingText.setFontFamily('retro'); |
| loadingText.setText('PRESS SPACE TO START'); |
| }); |
| } |
|
|
| create() { |
| |
| this.input.keyboard.once('keydown-SPACE', () => { |
| this.scene.start('GameScene'); |
| }); |
| } |
| } |
|
|
|
|