UNPKG

@dill-pixel/plugin-matter-physics

Version:

Matter Physics

87 lines 2.75 kB
import { Container, PointLike, Size, SizeLike } from 'dill-pixel'; import { default as Matter, IBodyDefinition, Vector } from 'matter-js'; import { Container as PIXIContainer } from 'pixi.js'; import { IMatterPhysicsObject } from './interfaces'; import { System } from './System'; import { MatterBodyType } from './types'; export type CollisionCallback = (other: Matter.Body) => void; export type PartConfig = { type: MatterBodyType; x: number; y: number; width: number; height: number; bodyDefinition?: Partial<IBodyDefinition>; }; export type EntityConfig = { bodyType?: MatterBodyType; size?: Size; view?: PIXIContainer; bodyDefinition?: Partial<IBodyDefinition>; debugColor?: number; parts?: PartConfig[]; rotationBehavior?: 'none' | 'follow' | 'firstPart'; offset?: PointLike; }; export declare class Entity extends Container implements IMatterPhysicsObject { config: Partial<EntityConfig>; static readonly DEFAULT_DEBUG_COLOR: number; body: Matter.Body; view: PIXIContainer; bodyType: MatterBodyType; bodyDefinition: Partial<IBodyDefinition>; debugColor: number; protected _offset: { x: number; y: number; }; protected _isDestroyed: boolean; protected isGrounded: boolean; protected onLandCallbacks: CollisionCallback[]; protected groundSensorHeight: number; protected rotationBehavior: 'none' | 'follow' | 'firstPart'; get system(): typeof System; get velocity(): Vector; get matter(): typeof Matter; set offset(value: PointLike); get offset(): { x: number; y: number; }; constructor(config?: Partial<EntityConfig>); added(): void; onRemoved(): void; destroy(): void; setSize(width: number, height: number): void; set size(size: SizeLike); createBody(): void; setVelocity(v: PointLike): void; setVelocityX(x: number): void; setVelocityY(y: number): void; /** * Sets up collision detection for the entity */ protected setupCollisionDetection(): void; /** * Handles the start of a collision */ protected handleCollisionStart(otherBody: Matter.Body, pair: Matter.Pair): void; /** * Handles the end of a collision */ protected handleCollisionEnd(otherBody: Matter.Body, pair: Matter.Pair): void; /** * Register a callback for when the entity lands */ onLand(callback: CollisionCallback): void; /** * Returns whether the entity is currently on the ground */ getIsGrounded(): boolean; /** * Locks the rotation of the physics body, keeping it upright */ lockRotation(): void; update(): void; } //# sourceMappingURL=Entity.d.ts.map