src/main.js
import './styles.css'
import Phaser from 'phaser'
class HelloScene extends Phaser.Scene {
create() {
const text = this.add
.text(this.scale.width / 2, this.scale.height / 2, 'Hello, Phaser ' + Phaser.VERSION, {
fontFamily: 'system-ui, sans-serif',
fontSize: '32px',
color: '#f6f7ff',
})
.setOrigin(0.5)
// The canvas is the whole pane (Scale.RESIZE), so keep the text centred.
this.scale.on('resize', ({ width, height }) => text.setPosition(width / 2, height / 2))
this.game.canvas.dataset.gameReady = 'true'
}
}
/** @type {Phaser.Types.Core.GameConfig} */
const config = {
type: Phaser.AUTO,
parent: 'game',
width: '100%',
height: '100%',
backgroundColor: '#0b1020',
scale: { mode: Phaser.Scale.RESIZE },
scene: HelloScene,
}
new Phaser.Game(config)