import GameObject from '../core/GameObject.js'; import Vector2 from '../math/Vector2.js'; /** * Configuration for creating a Sprite object. */ export interface SpriteProps { /** Unique tag for the object. */ tag: string; /** Hidden identifier linking runtime object to its source code location. */ __sourceId?: string; /** Image instance or tag from ResourceLoader. */ img: HTMLImageElement | string; /** Number of rows in the spritesheet. */ rows: number; /** Number of columns in the spritesheet. */ cols: number; /** Starting column index for the animation (0-based). */ startCol?: number; /** Ending column index for the animation (0-based). */ endCol?: number; /** Initial position in world space. */ position?: Vector2; /** Rendering order. */ zIndex?: number; /** Scale factor (number or Vector2). */ scale?: number | Vector2; /** Whether the sprite is initially visible. */ visible?: boolean; /** Initial physics configuration. */ physics?: { velocity?: Vector2; acceleration?: Vector2; mass?: number; isStatic?: boolean; restitution?: number; friction?: number; isSensor?: boolean; }; } /** * A high-level object that represents an animated sprite. * Wraps SpriteComponent and TransformComponent for ease of use. */ export default class Sprite extends GameObject { private _spriteComponent; /** The image element used by the sprite. */ get img(): HTMLImageElement; set img(val: HTMLImageElement); /** Number of rows in the spritesheet. */ get rows(): number; set rows(val: number); /** Number of columns in the spritesheet. */ get cols(): number; set cols(val: number); /** The starting column for the current animation loop. */ get startCol(): number; set startCol(val: number); /** The ending column for the current animation loop. */ get endCol(): number; set endCol(val: number); /** The pixel width of a single animation frame (calculated automatically). */ get frameWidth(): number; /** Pixel height of a single animation frame (calculated automatically). */ get frameHeight(): number; /** Whether the sprite is currently registered with the engine. */ registered: boolean; /** The current frame index being displayed. */ get currentFrame(): number; set currentFrame(val: number); /** Whether the sprite is horizontally flipped. */ get flip(): boolean; set flip(val: boolean); /** Duration of each animation frame in milliseconds. */ get frameDuration(): number; set frameDuration(val: number); /** * Gets or sets the scale of the sprite. * Returns the world-space scale of the transform. */ get scale(): Vector2; set scale(val: number | Vector2); /** * initialises a new instance of a Sprite. * @param props Configuration properties for the sprite. */ constructor(props: SpriteProps); /** * Updates the bounds of the sprite based on its current frame size. * Note: Bounds represent the BASE local size (unscaled). * @private */ private _updateBounds; /** * Registers the sprite with the engine and starts its animation loop. */ play(): void; /** * Stops the sprite's animation and removes it from the engine. */ stop(): void; }