/** * additional import for TypeScript * @import { TextureAtlas } from "../video/texture/atlas.js"; * @import { Vector2d } from "../math/vector2d.js"; */ /** * The shared **frame-animation engine** behind {@link Sprite} (2D) and * {@link Sprite3d} (3D billboards). It *owns* the animation state — definitions, * the current frame, timing, looping and chaining — everything independent of * how a frame is ultimately *drawn*, and drives its host renderable through a * small contract: * * - it reads the host's resolved texture (`host.source`, `host.textureAtlas`, * `host.atlasIndices`) to turn a frame index/name into a region; * - it calls the `applyFrame(region)` callback passed to the constructor whenever * the frame changes — the host applies it to its own geometry ({@link Sprite} * swaps its source sub-texture, size and anchor; {@link Sprite3d} maps the * region onto its quad's UVs + vertices) **and marks itself dirty there**; * - it fires `host.onended()` at each cycle end. * * The engine owns no dirty flag: a frame change flows through `applyFrame`, where * the host sets its own `isDirty`. Callers read dirtiness from the host (the * host's `update()` returns `super.update()` → `isDirty`). * * Hosts expose the public-facing state (`anim`, `current`, `animationspeed`, * `animationpause`, …) as thin accessors onto this engine, so 2D and 3D frame * animation share one implementation with no behavioral fork. * @category Animation */ export default class FrameAnimation { /** * @param {object} host - the renderable this engine drives. Read for the * texture it animates (`source` / `textureAtlas` / `atlasIndices`) and the * mutable cycle-end callback (`onended`). These are read lazily (the texture is * usually resolved after the engine is constructed), which is why they live on * the host rather than being passed in. The engine does not touch `isDirty` — * the host marks itself dirty inside `applyFrame`. * @param {(region: object) => void} applyFrame - called whenever the frame * changes, with the selected texture region; the host applies it to its own * geometry (a {@link Sprite} swaps its sub-texture / size / anchor, a * {@link Sprite3d} remaps its quad's UVs + vertices). */ constructor(host: object, applyFrame: (region: object) => void); /** defined animations, keyed by id @type {object} */ anim: object; /** current frame info @type {object} */ current: object; /** elapsed time within the current frame, in ms @type {number} */ dt: number; /** default frame cycling speed (ms between frames) @type {number} */ animationspeed: number; /** pause flag — freezes the current frame @type {boolean} */ animationpause: boolean; /** * add an animation definition (see {@link Sprite#addAnimation}). * @param {string} name - animation id * @param {number[]|string[]|object[]} index - frame indices / names / objects * @param {number} [animationspeed] - cycling speed in ms * @returns {number} number of frames added (0 if no texture atlas) */ addAnimation(name: string, index: number[] | string[] | object[], animationspeed?: number): number; /** * select the active animation (see {@link Sprite#setCurrentAnimation}). * @param {string} name - animation id * @param {string|Function|object} [resetAnim] - loop / chain / completion behavior * @param {boolean} [preserve_dt=false] - keep the elapsed-frame timer * @returns {object} the host (for method chaining) */ setCurrentAnimation(name: string, resetAnim?: string | Function | object, preserve_dt?: boolean): object; /** * reverse the given (or current) animation in place (see {@link Sprite#reverseAnimation}). * The host marks itself dirty (this path doesn't re-apply a frame, so it's the * one place a host's `reverseAnimation` wrapper sets `isDirty`). * @param {string} [name] - animation id */ reverseAnimation(name?: string): void; /** * @param {string} name - animation id * @returns {boolean} true if `name` is the current animation */ isCurrentAnimation(name: string): boolean; /** * @returns {string[]} the names of every defined animation */ getAnimationNames(): string[]; /** * apply a texture region as the current frame: store its geometry into * `current` and hand it to the host to draw (see {@link Sprite#setRegion}). * @param {object} region - the texture region object * @returns {object} the host (for method chaining) */ setRegion(region: object): object; /** * force the current animation frame index (see {@link Sprite#setAnimationFrame}). * @param {number} [index=0] - animation frame index * @returns {object} the host (for method chaining) */ setAnimationFrame(index?: number): object; /** * @returns {number} the current animation frame index */ getCurrentAnimationFrame(): number; getAnimationFrameObjectByIndex(id: any): any; /** * clear the frame timer and the play-once "done" hold, without changing the * current frame (the timer half of a stop, used by the video path which has * no frame to rewind to). */ resetTimer(): void; /** * reset the current animation to its first frame (the frame-animation half of * {@link Sprite#stop} — the host still handles any video / pause concerns). */ rewind(): void; /** * advance the frame animation by `dt` milliseconds, stepping frames, looping * and chaining as configured (see {@link Sprite#update}). On a frame change the * host marks itself dirty via `_applyFrame` (the engine owns no dirty flag); * this returns whether a frame actually changed this tick — a finer-grained * signal than the host's `isDirty` (which means "needs redraw for any reason"). * @param {number} dt - elapsed time since the last update, in milliseconds * @returns {boolean} true if a frame changed this tick */ update(dt: number): boolean; /** * release engine-held resources — returns the pooled `current.offset` * Vector2d to the pool. Call from the host's `destroy()`. */ destroy(): void; } //# sourceMappingURL=frameAnimation.d.ts.map