UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

72 lines (71 loc) 2.57 kB
import { type ITime } from './engine_types.js'; /** * Provides time-related information for frame-based game logic. * Access via `this.context.time` from any component. * * @example Using deltaTime for frame-rate independent movement * ```ts * update() { * // Move 1 unit per second regardless of frame rate * this.gameObject.position.x += 1 * this.context.time.deltaTime; * } * ``` * @example Checking elapsed time * ```ts * start() { * console.log(`Time since start: ${this.context.time.time}s`); * console.log(`Current frame: ${this.context.time.frameCount}`); * } * ``` */ export declare class Time implements ITime { /** The time in seconds since the start of Needle Engine. */ get time(): number; private set time(value); private _time; /** The time in seconds it took to complete the last frame (Read Only). */ get deltaTime(): number; private set deltaTime(value); private _deltaTime; /** The time in seconds it took to complete the last frame (Read Only). Timescale is not applied. */ get deltaTimeUnscaled(): number; private _deltaTimeUnscaled; /** * The scale at which time passes. Default is 1. * - Values < 1 create slow motion (e.g. 0.5 = half speed) * - Values > 1 speed up time (e.g. 2 = double speed) * - Value of 0 effectively pauses time-dependent logic */ timeScale: number; /** same as frameCount */ get frame(): number; private set frame(value); private _frame; /** The total number of frames that have passed (Read Only). Same as frame */ get frameCount(): number; /** The time in seconds it took to complete the last frame (Read Only). */ get realtimeSinceStartup(): number; /** * @returns {Number} FPS for this frame. * Note that this returns the raw value (e.g. 59.88023952362959) and will fluctuate a lot between frames. * If you want a more stable FPS, use `smoothedFps` instead. */ get fps(): number; /** * Approximated frames per second * @returns the smoothed FPS value over the last 60 frames with decimals. */ get smoothedFps(): number; /** The smoothed time in seconds it took to complete the last frame (Read Only). */ get smoothedDeltaTime(): number; private clock; private _smoothedFps; private _smoothedDeltaTime; private readonly _fpsSamples; private _fpsSampleIndex; constructor(); /** Step the time. This is called automatically by the Needle Engine Context. * @internal */ update(): void; }