frontispiece / packages / phaser-bgs / example / index.ts
index.ts
Raw
import "./index.css"

import * as Phaser from 'phaser'

import cabin from "./assets/cabin.webp"
import lounge from "./assets/lounge.webp"
import { DissolveTransition, PhaserBGEngine } from "../src"

var scene = new Phaser.Scene({
	key: 'start'
})

// create a game
const game = new Phaser.Game({
	type: Phaser.WEBGL,
	width: 800,
	height: 600,
	scale: {
		mode: Phaser.Scale.ScaleModes.RESIZE,
	},
	scene: [scene]
})


const engine = new PhaserBGEngine(
	{
		cabin,
		lounge,
	},
	{
		autoResizeBGs: true,
		autoResizeGame: false,
	},
	game
)

window.addEventListener("keydown", (e) => {
	if (e.key === "a") {
		engine.transition("cabin", {
			duration: 500,
		})
	} else if (e.key === "d") {
		engine.transition("lounge", DissolveTransition(engine.scene, 500))
	} else if (e.key === "s") {
		engine.transitionColor(0xffffff, {
			duration: 500,
		})
	} else if (e.key === "w") {
		engine.transitionColor(0x000000, DissolveTransition(engine.scene, 500))
	}
})