UNPKG

@knopkem/little-game-engine-ts

Version:

LittleGameEngineTS - Tiny and Fast HTML5 Game Engine typescript port of LittleJS

122 lines (121 loc) 5.63 kB
import { EngineObject } from './index'; import { Color, Vector2 } from './index'; /** * LittleJS Tile Layer System * <br> - Caches arrays of tiles to offscreen canvas for fast rendering * <br> - Unlimted numbers of layers, allocates canvases as needed * <br> - Interfaces with EngineObject for collision * <br> - Collision layer is separate from visible layers * <br> - Tile layers can be drawn to using their context with canvas2d * <br> - It is recommended to have a visible layer that matches the collision * @namespace TileLayer */ export declare let tileCollision: Array<any>, tileCollisionSize: Vector2; /** Clear and initialize tile collision * @param {Vector2} size * @memberof TileLayer */ export declare function initTileCollision(size: any): void; /** Set tile collision data * @param {Vector2} pos * @param {Number} [data=0] * @memberof TileLayer */ export declare const setTileCollisionData: (pos: any, data?: number) => any; /** Get tile collision data * @param {Vector2} pos * @return {Number} * @memberof TileLayer */ export declare const getTileCollisionData: (pos: any) => any; /** Check if collision with another object should occur * @param {Vector2} pos * @param {Vector2} [size=new Vector2(1,1)] * @param {EngineObject} [object] * @return {Boolean} * @memberof TileLayer */ export declare function tileCollisionTest(pos: any, size: Vector2 | undefined, object: any): boolean; /** Return the center of tile if any that is hit (this does not return the exact hit point) * @param {Vector2} posStart * @param {Vector2} posEnd * @param {EngineObject} [object] * @return {Vector2} * @memberof TileLayer */ export declare function tileCollisionRaycast(posStart: any, posEnd: any, object: any): Vector2 | undefined; export declare const tileLayerCanvasCache: Array<any>; /** Tile layer data object stores info about how to render a tile */ export declare class TileLayerData { color: any; direction: any; mirror: any; tile: any; /** Create a tile layer data object * @param {Number} [tile] - The tile to use, untextured if undefined * @param {Number} [direction=0] - Integer direction of tile, in 90 degree increments * @param {Boolean} [mirror=0] - If the tile should be mirrored along the x axis * @param {Color} [color=new Color(1,1,1)] - Color of the tile */ constructor(tile: any, direction?: number, mirror?: number, color?: Color); /** Set this tile to clear, it will not be rendered */ clear(): void; } /** Tile layer object - cached rendering system for tile layers */ export declare class TileLayer extends EngineObject { canvas: any; context: any; data: any; flushGLBeforeRender: any; savedRenderSettings: any; scale: any; /** Create a tile layer data object * @param {Vector2} [position=new Vector2(0,0)] - World space position * @param {Vector2} [size=defaultObjectSize] - World space size * @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this in world space * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered */ constructor(pos: any, size: any, scale?: Vector2, renderOrder?: number); /** Destroy this tile layer */ destroy(): void; /** Set data at a given position in the array * @param {Vector2} position - Local position in array * @param {TileLayerData} data - Data to set * @param {Boolean} [redraw=0] - Force the tile to redraw if true */ setData(layerPos: any, data: any, redraw: any): void; /** Get data at a given position in the array * @param {Vector2} layerPos - Local position in array * @return {TileLayerData} */ getData(layerPos: any): any; update(): void; render(): void; /** Draw all the tile data to an offscreen canvas using webgl if possible */ redraw(): void; /** Call to start the redraw process * @param {Boolean} [clear=1] - Should it clear the canvas before drawing */ redrawStart(clear?: number): void; /** Call to end the redraw process */ redrawEnd(): void; /** Draw the tile at a given position * @param {Vector2} layerPos */ drawTileData(layerPos: any): void; /** Draw all the tiles in this layer */ drawAllTileData(): void; /** Draw directly to the 2d canvas in world space (bipass webgl) * @param {Vector2} pos * @param {Vector2} size * @param {Number} angle * @param {Boolean} mirror * @param {Function} drawFunction */ drawCanvas2D(pos: any, size: any, angle: any, mirror: any, drawFunction: any): void; /** Draw a tile directly onto the layer canvas * @param {Vector2} pos * @param {Vector2} [size=new Vector2(1,1)] * @param {Number} [tileIndex=-1] * @param {Vector2} [tileSize=defaultTileSize] * @param {Color} [color=new Color(1,1,1)] * @param {Number} [angle=0] * @param {Boolean} [mirror=0] */ drawTile(pos: any, size: Vector2 | undefined, tileIndex: number | undefined, tileSize: Vector2 | undefined, color: Color | undefined, angle: number | undefined, mirror: any): void; /** Draw a rectangle directly onto the layer canvas * @param {Vector2} pos * @param {Vector2} [size=new Vector2(1,1)] * @param {Color} [color=new Color(1,1,1)] * @param {Number} [angle=0] */ drawRect(pos: any, size: any, color: any, angle: any): void; }