UNPKG

@hiddentao/clockwork-engine

Version:

A TypeScript/PIXI.js game engine for deterministic, replayable games with built-in rendering

38 lines (37 loc) 1.18 kB
/** * Web Platform Layer * * Browser-based platform implementation composing Web-specific layers. */ import { PixiRenderingLayer } from "./PixiRenderingLayer"; import { WebAudioLayer } from "./WebAudioLayer"; import { WebInputLayer } from "./WebInputLayer"; export class WebPlatformLayer { constructor(container, options) { this.canvas = document.createElement("canvas"); this.canvas.width = options.screenWidth; this.canvas.height = options.screenHeight; container.appendChild(this.canvas); this.rendering = new PixiRenderingLayer(this.canvas, options); this.audio = new WebAudioLayer(); this.input = new WebInputLayer(container, this.audio); } async init() { await this.rendering.init(); await this.audio.initialize(); } destroy() { this.rendering.destroy(); this.audio.destroy(); this.input.removeAllListeners(); if (this.canvas.parentNode) { this.canvas.parentNode.removeChild(this.canvas); } } getDevicePixelRatio() { return window.devicePixelRatio || 1; } getCanvas() { return this.canvas; } }