import { Component } from './component'; import { RigidBody } from './components/rigidBody'; import { EntityPool } from './entityPool'; import { ImAnimation } from './imAnimation'; import { ObjectLayer } from './level/objectLayer'; import { SpriteSheet } from './spriteSheet'; import { AnimationOptions, EntitySettings, TileType, Vector2 } from './types'; export declare class Entity { static entities: Entity[]; static pool: EntityPool; static classId: number; static updateAllEntities(delta: number): void; /** * Sort entities by their z-index */ static sortEntities(): void; /** * Finds and returns an Entity by its name */ static findByName(name: string): Entity; readonly id: number; name?: string; zIndex: number; x: number; y: number; width: number; height: number; spriteSheet?: SpriteSheet; anims: { [index: string]: ImAnimation; }; /** * Set to true to activate pooling for your Entity subclass */ pooling: boolean; /** * The array referencing components owned by this entity. * Automatically managed by the engine, so you shouldn't have to touch it. */ components: Component[]; /** * An offset in pixels for the sprite's placement. * Does not affect the collision box */ offset: Vector2; /** * Entities "live" on an ObjectLayer inside the current Level */ layer?: ObjectLayer; /** * An instance of the RigidBody component, * used to manage basic physics and collisions */ rigidBody: RigidBody; private _currentAnim?; readonly currentAnim: ImAnimation | undefined; /** * Creates an instance of Entity. */ constructor(settings: EntitySettings); /** * Applies the settings for an entity. * This method is automatically called for revived pooled entities. * Use it to reset their state */ reset(settings: EntitySettings): void; draw(): void; /** * Adds an animation for the current spriteSheet * * @param {string} name * @param {number} frameDuration Duration of each frame in milliseconds * @param {TileType[]} sequence An Array of either frame positions (`[0, 1, 2]`) or set of coordinates (`[[0, 0], [8, 0], [16, 0]]`) * @param {AnimationOptions} [options] * @returns {ImAnimation} * @memberof Entity */ addAnimation(name: string, frameDuration: number, sequence: TileType[], options?: AnimationOptions): ImAnimation; setAnimation(animation: ImAnimation): void; /** * Returns the angle from this entity's center to the other entity's center. */ angleTo(other: Entity): number; distanceTo(other: Entity): number; /** * Returns true if this entity collides with another. * Uses a simple aabb algorithm */ touches(other: Entity): boolean; /** * Alias of `game.removeEntity()` */ kill(): void; /** * Adds a Component instance */ addComponent(component: Component): void; /** * Removes a component and triggers its removed(entity) callback */ removeComponent(component: Component): Entity; /** * Returns the list of components that match the class * * @param {new (...args: any[]) => T} ctor The component's class * @returns {(T[])} The array of components */ getComponents(ctor: new (...args: any[]) => T): T[]; /** * Returns the first component that matches the class * * @param {new (...args: any[]) => T} ctor The Component's class * @example entity.getComponent(RigidBody) * @returns {(T | undefined)} The first corresponding component. Undefined if none is found */ getComponent(ctor: new (...args: any[]) => T): T | undefined; getFoo(): string; /** * Triggered when a collision occurs between this entity and another * * @param {Entity} other * @memberof Entity */ onCollision(other: Entity): void; /** * Public update method. Call this on your own Entity subclasses * to implement logic */ protected update(delta: number): void; private _update; private updateComponents; private updateAnimations; }