UNPKG

artistic-engine

Version:

General purpose html5 canvas rendering game engine

60 lines (59 loc) 2.33 kB
import CanvasConfig from "./canvas_config"; import { Vector2D } from "./vector"; import { Scene } from "./sprite"; import { Modifier } from "./modifiers/modifiers"; import { Transform } from "./transform"; import { AssetLoader } from "./loader"; export default class Engine { private canvas; private context; private previousTimestamp; private animationId; private scene; private subReset; private camera; private modifiers; private assetLoader; /** * Constructor will bind Engine object to a given canvas and check for incompatible canvas features and cover. * @param canvasIdentifier one of HTMLCnavasElement or css selector string that indicates canvas element. */ constructor(canvasIdentifier: HTMLCanvasElement | string | null, canvasConfig?: CanvasRenderingContext2DSettings); get Canvas(): HTMLCanvasElement; get Context(): CanvasRenderingContext2D; get Scene(): Scene; get Camera(): Transform; get AssetLoader(): AssetLoader; set Scene(scene: Scene); set Camera(camera: Transform); set AssetLoader(assetLoader: AssetLoader); /** * Register a callback that will be called on each frame. * @param func User defined callback that will be executed after each frame is reset completely */ setSubResetFunction(func: (context: CanvasRenderingContext2D) => void): void; /** * Set canvas width and height to given dimension. Canvas will try to match window size when no arguments are passed. * @param config Canvas size dimension. */ resizeCanvas(config?: CanvasConfig | Vector2D): void; /** * Makes bound canvas begin refreshing with given context. This will also start modifiers to update. */ start(): void; /** * Makes bound canvas to stop refreshing. This will also stop modifiers to update. */ stop(): void; /** * Register and start given modifier from this engine. * @param modifier Modifier to halt execution. */ registerModifier(modifier: Modifier): void; /** * Stops and removes given modifier from update pool in this engine. * @param modifier Modifier to halt execution. */ unregisterModifier(modifier: Modifier): void; private render; }