typed-loop
Version:
A loop class to enable flexible intervals for visual experiments and games. It provides delta time in various formats and uses `requestAnimationFrame` for the timeouts. It's possible to use `setTimeout` with given `targetDeltaTime`.
31 lines (30 loc) • 888 B
TypeScript
export declare enum DeltaTimeFormat {
RELATIVE = "relative",
MILLISECONDS = "milliseconds",
SECONDS = "seconds"
}
export interface LoopParameters {
onTick: (deltaTime: number) => any;
deltaTimeFormat?: DeltaTimeFormat;
deltaTimeLimit?: number;
startWithoutDelay?: boolean;
targetTimeout?: number;
}
export declare class Loop {
onTick: (deltaTime: number) => any;
private lastTickTime;
private active;
private deltaTimeFormat;
private deltaTimeLimit;
private startWithoutDelay;
private timeoutFunction;
private targetTimeout;
private timeoutId;
static estimatedDeltaTimeMs: number;
constructor({ onTick, deltaTimeLimit, targetTimeout, deltaTimeFormat, startWithoutDelay, }: LoopParameters);
start(): this;
stop(): void;
private tick;
private getFormattedDeltaTime;
private scheduleNextTick;
}