@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
185 lines • 5.87 kB
TypeScript
/**
* Describes change of a numeric value over time.
* Values are stored in {@link Keyframe}s, interpolation is defined by tangents on {@link Keyframe}s.
* The curve is a cubic Hermite spline.
*
* @example
* const jump_curve = AnimationCurve.from([
* Keyframe.from(0, 0), // start at height 0
* Keyframe.from(0.3, 2), // at time 0.3, jump height will be 2 meters
* Keyframe.from(1, 0) // at time 1.0, land back on the ground
* ]);
*
* jump_curve.evaluate(0.1); // what is the height at time 0.1?
*
* @example
* const curve = AnimationCurve.easeInOut();
*
* sprite.transparency = curve.evaluate(time); // smoothly animate transparency of the sprite
*
* @implements Iterable<Keyframe>
*
* @see https://en.wikipedia.org/wiki/Cubic_Hermite_spline.
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class AnimationCurve implements Iterable<Keyframe> {
/**
* Utility constructor
* @param {Keyframe[]} keys
* @returns {AnimationCurve}
*/
static from(keys: Keyframe[]): AnimationCurve;
/**
* S-shaped curve that starts slowly, ramps up and flattens out again.
* Useful for pleasing transitions where exit and entry should not be abrupt.
*
* @param {number} [timeStart]
* @param {number} [valueStart]
* @param {number} [timeEnd]
* @param {number} [valueEnd]
* @return {AnimationCurve}
*/
static easeInOut(timeStart?: number, valueStart?: number, timeEnd?: number, valueEnd?: number): AnimationCurve;
/**
* A flat-line curve with a specific start and end time
* @param {number} [timeStart]
* @param {number} [timeEnd]
* @param {number} [value]
* @return {AnimationCurve}
*/
static constant(timeStart?: number, timeEnd?: number, value?: number): AnimationCurve;
/**
* Curve with two keyframes connected by a straight line
* @param {number} [timeStart]
* @param {number} [valueStart]
* @param {number} [timeEnd]
* @param {number} [valueEnd]
* @return {AnimationCurve}
*/
static linear(timeStart?: number, valueStart?: number, timeEnd?: number, valueEnd?: number): AnimationCurve;
/**
* Keyframes defining the curve, in chronological order.
* The curve manages the contents of this array, do not modify it directly.
* @readonly
* @type {Keyframe[]}
*/
readonly keys: Keyframe[];
/**
* Add a new keyframe into the animation.
* Keyframes can be added out of order, they will be inserted into the correct chronological position.
* @param {Keyframe} key
* @returns {number} key index where it was inserted at
*/
add(key: Keyframe): number;
/**
* Insert multiple keyframes. Input doesn't need to be sorted.
* @param {Keyframe[]} keys
*/
addMany(keys: Keyframe[]): void;
/**
*
* @param {Keyframe} key
* @returns {boolean} true if the key was removed, false if the key was not found
*/
remove(key: Keyframe): boolean;
/**
* Remove all keys, making the curve empty.
*/
clear(): void;
/**
* Does this curve have any keyframes?
* @return {boolean} true iff keyframe count == 0, false otherwise
*/
isEmpty(): boolean;
/**
* Number of keyframes in the curve.
* @returns {number}
*/
get length(): number;
/**
* Timestamp of the first keyframe.
* Returns 0 if there are no keyframes.
* @returns {number}
*/
get start_time(): number;
/**
* Time of the last chronological key in the curve.
* Returns 0 if there are no keyframes.
* @return {number}
*/
get end_time(): number;
/**
* Time difference between the first and the last keyframe.
* Returns 0 if there are no keyframes.
* @returns {number}
*/
get duration(): number;
/**
* Returns index of a key that is just before or at the time specified.
* Useful for insertion and evaluation logic.
* Note: if time is past the end of last key - index of the last key will be returned instead
* @param {number} time
* @returns {number} index of the key
*/
getKeyIndexLow(time: number): number;
/**
* Evaluate interpolated value across the curve at a given time.
* @param {number} time time in seconds
* @return {number} value at the specified time
*/
evaluate(time: number): number;
/**
* Set tangents of a key to match surrounding keys
* Produces a smoother looking curve
* @param {number} index index of keyframe
*/
alignTangents(index: number): void;
/**
*
* @param {number} index Index of keyframe to be affected
* @param {number} weight How much smoothing to apply, 1 will be fully smoothed out and 0 will have no effect at all. Value between 0 and 1
*/
smoothTangents(index: number, weight: number): void;
smoothAllTangents(): void;
/**
* The copy is deep
* @param {AnimationCurve} other
*/
copy(other: AnimationCurve): void;
/**
*
* @return {AnimationCurve}
*/
clone(): AnimationCurve;
/**
*
* @param {AnimationCurve} other
* @return {boolean}
*/
equals(other: AnimationCurve): boolean;
/**
*
* @return {number}
*/
hash(): number;
toJSON(): {
keys: any[];
};
fromJSON({ keys }: {
keys?: any[];
}): void;
/**
* Useful for fast type checks
* @readonly
* @type {boolean}
*/
readonly isAnimationCurve: boolean;
/**
* @deprecated use `getKeyIndexLow` instead
*/
getKeyIndexByTime: (time: number) => number;
[Symbol.iterator](): Generator<Keyframe, void, unknown>;
}
import { Keyframe } from "./Keyframe.js";
//# sourceMappingURL=AnimationCurve.d.ts.map