UNPKG

@knopkem/little-game-engine-ts

Version:

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

101 lines (100 loc) 4.58 kB
import { Vector2 } from "./index"; /** * LittleJS Object Base Object Class * <br> - Base object class used by the engine * <br> - Automatically adds self to object list * <br> - Will be updated and rendered each frame * <br> - Renders as a sprite from a tilesheet by default * <br> - Can have color and addtive color applied * <br> - 2d Physics and collision system * <br> - Sorted by renderOrder * <br> - Objects can have children attached * <br> - Parents are updated before children, and set child transform * <br> - Call destroy() to get rid of objects */ export declare class EngineObject { additiveColor: any; angle: any; angleDamping: any; angleVelocity: any; children: any; collideSolidObjects: any; collideTiles: any; color: any; damping: any; destroyed: any; drawSize: any; elasticity: any; friction: any; gravityScale: any; groundObject: any; isSolid: any; localAngle: any; localPos: any; mass: any; mirror: any; parent: any; pos: any; renderOrder: any; size: any; spawnTime: any; tileIndex: any; tileSize: any; velocity: any; /** * Create an engine object and adds it to the list of objects * @param {Vector2} [position=new Vector2(0,0)] - World space position of the object * @param {Vector2} [size=defaultObjectSize] - World space size of the object * @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1 * @param {Vector2} [tileSize=defaultTileSize] - Size of tile in source pixels * @param {Number} [angle=0] - Angle to rotate the object * @param {Color} [color] - Color to apply to tile when rendered */ constructor(pos: Vector2 | undefined, size: Vector2 | undefined, tileIndex: number | undefined, tileSize: Vector2 | undefined, angle: number | undefined, color: any); /** Update the object transform and physics, called automatically by engine once each frame */ update(): void; /** Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder */ render(): void; /** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */ destroy(): void; /** Called to check if a tile collision should be resolved * @param {Number} tileData - the value of the tile at the position * @param {Vector2} pos - tile where the collision occured * @return {Boolean} true if the collision should be resolved */ collideWithTile(tileData: any, _pos: any): boolean; /** Called to check if a tile raycast hit * @param {Number} tileData - the value of the tile at the position * @param {Vector2} pos - tile where the raycast is * @return {Boolean} true if the raycast should hit */ collideWithTileRaycast(tileData: any, _pos: any): boolean; /** Called to check if a tile raycast hit * @param {EngineObject} object - the object to test against * @return {Boolean} true if the collision should be resolved */ collideWithObject(_o: any): boolean; /** How long since the object was created * @return {Number} */ getAliveTime(): number; /** Apply acceleration to this object (adjust velocity, not affected by mass) * @param {Vector2} acceleration */ applyAcceleration(a: any): void; /** Apply force to this object (adjust velocity, affected by mass) * @param {Vector2} force */ applyForce(force: any): void; /** Get the direction of the mirror * @return {Number} -1 if this.mirror is true, or 1 if not mirrored */ getMirrorSign(): 1 | -1; /** Attaches a child to this with a given local transform * @param {EngineObject} child * @param {Vector2} [localPos=new Vector2] * @param {Number} [localAngle=0] */ addChild(child: any, localPos?: Vector2, localAngle?: number): void; /** Removes a child from this one * @param {EngineObject} child */ removeChild(child: any): void; /** Set how this object collides * @param {boolean} [collideSolidObjects=0] - Does it collide with solid objects * @param {boolean} [isSolid=0] - Does it collide with and block other objects (expensive in large numbers) * @param {boolean} [collideTiles=1] - Does it collide with the tile collision */ setCollision(collideSolidObjects?: number, isSolid?: number, collideTiles?: number): void; }