import { EasingFunction } from "./easing.js"; import { InterpolationFunction } from "./interpolation.js"; /** @ignore */ type OnStartCallback = (this: T) => void; /** @ignore */ type OnUpdateCallback = (this: T, value: number) => void; /** @ignore */ type OnCompleteCallback = (this: T) => void; /** * A tweening engine for smoothly interpolating object properties over time. * Based on tween.js with * optimised Robert Penner's equations. * * Tweens use an event-based lifecycle — on `start()` the tween subscribes to * the game loop events (`TICK`, `GAME_AFTER_UPDATE`, `STATE_PAUSE`, * `STATE_RESUME`, `GAME_RESET`) * and automatically unsubscribes on completion or `stop()`. * They do not need to be added to a container. * @example * // basic usage * new me.Tween(myObject.pos) * .to({ x: 200, y: 200 }, { duration: 3000, easing: me.Tween.Easing.Bounce.Out }) * .onComplete(() => console.log("done!")) * .start(); * @example * // auto-start with options * new me.Tween(myObject.pos).to({ x: 200 }, { * duration: 1000, * easing: me.Tween.Easing.Quadratic.InOut, * yoyo: true, * repeat: Infinity, * autoStart: true, * }); * @category Tweens */ export default class Tween { _object: object; _valuesStart: Record; _valuesEnd: Record; _valuesStartRepeat: Record; _duration: number; _repeat: number; _yoyo: boolean; _reversed: boolean; _delayTime: number; _startTime: number | null; _easingFunction: EasingFunction; _interpolationFunction: InterpolationFunction; _chainedTweens: Array; _onStartCallback: OnStartCallback | null; _onStartCallbackFired: boolean; _onUpdateCallback: OnUpdateCallback | null; _onCompleteCallback: OnCompleteCallback | null; _tweenTimeTracker: number; _lastUpdate: number; _isRunning: boolean; _isPaused: boolean; _lastTick: number; /** * whether the tween should persist across state changes (not auto-stopped on game reset) * @default false */ isPersistent: boolean; /** * whether the tween should keep running when the game is paused * @default false */ updateWhenPaused: boolean; /** * @param object - the object whose properties will be tweened */ constructor(object: object); /** * @ignore */ onResetEvent(object: object): void; /** * @ignore */ setProperties(object: object): void; /** * @ignore */ _resumeCallback(elapsed: number): void; /** @ignore */ _onAfterUpdate(lastUpdate: number): void; /** @ignore */ _onTick(timestamp: number): void; /** @ignore */ _onPause(): void; /** @ignore */ _onReset(): void; /** * Subscribe to the game loop events * @ignore */ _subscribe(): void; /** * Unsubscribe from the game loop events * @ignore */ _unsubscribe(): void; /** * Define the target property values and tween options. * @param properties - target property values to tween to (e.g. `{ x: 200, y: 100 }`) * @param [options] - tween configuration * @param [options.duration] - tween duration in milliseconds * @param [options.easing] - easing function (e.g. `Tween.Easing.Quadratic.InOut`) * @param [options.delay] - delay before starting, in milliseconds * @param [options.yoyo] - bounce back to original values when finished (use with `repeat`) * @param [options.repeat] - number of times to repeat (use `Infinity` for endless loops) * @param [options.interpolation] - interpolation function for array values * @param [options.autoStart] - start the tween immediately without calling `start()` * @returns this instance for object chaining */ to(properties: Record, options?: { duration?: number | undefined; easing?: EasingFunction | undefined; yoyo?: boolean | undefined; repeat?: number | undefined; delay?: number | undefined; interpolation?: InterpolationFunction | undefined; autoStart?: boolean | undefined; }): this; /** * Start the tween. Subscribes to game loop events and begins interpolation. * @param [time] - the start time (defaults to current game time) * @returns this instance for object chaining */ start(time?: number): this; /** * Stop the tween. Unsubscribes from all game loop events. * @returns this instance for object chaining */ stop(): this; /** * delay the tween * @param amount - delay amount expressed in milliseconds * @returns this instance for object chaining */ delay(amount: number): this; /** * Repeat the tween * @param times - amount of times the tween should be repeated * @returns this instance for object chaining */ repeat(times: number): this; /** * Allows the tween to bounce back to their original value when finished. * To be used together with repeat to create endless loops. * @param yoyo flag * @returns this instance for object chaining */ yoyo(yoyo: boolean): this; /** * set the easing function * @param easing - easing function * @returns this instance for object chaining */ easing(easing: EasingFunction): this; /** * set the interpolation function * @param interpolation - interpolation function * @returns this instance for object chaining */ interpolation(interpolation: InterpolationFunction): this; /** * chain the tween * @param tweens - Tween(s) to be chained * @returns this instance for object chaining */ chain(...tweens: Tween[]): this; /** * onStart callback * @param onStartCallback - callback * @returns this instance for object chaining */ onStart(onStartCallback: OnStartCallback): this; /** * onUpdate callback * @param onUpdateCallback - callback * @returns this instance for object chaining */ onUpdate(onUpdateCallback: OnUpdateCallback): this; /** * onComplete callback * @param onCompleteCallback - callback * @returns this instance for object chaining */ onComplete(onCompleteCallback: OnCompleteCallback): this; /** @ignore */ update(dt: number): boolean; /** * Available easing functions, accessed via `Tween.Easing`. * Each family provides `In`, `Out`, and `InOut` variants. * @see {@link Easing} for the full list * @example * me.Tween.Easing.Quadratic.InOut * me.Tween.Easing.Bounce.Out * me.Tween.Easing.Elastic.In */ static get Easing(): { Linear: { None: (k: number) => number; }; Quadratic: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; Cubic: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; Quartic: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; Quintic: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; Sinusoidal: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; Exponential: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; Circular: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; Elastic: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; Back: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; Bounce: { In: (k: number) => number; Out: (k: number) => number; InOut: (k: number) => number; }; }; /** * Available interpolation functions for tweening array values. * @see {@link Interpolation} * @example * me.Tween.Interpolation.Linear * me.Tween.Interpolation.Bezier * me.Tween.Interpolation.CatmullRom */ static get Interpolation(): { Linear: (v: number[], k: number) => number; Bezier: (v: number[], k: number) => number; CatmullRom: (v: number[], k: number) => number; }; } export declare const tweenPool: import("../system/pool.ts").Pool; export {}; //# sourceMappingURL=tween.d.ts.map