Effect Management
This module provides a utility function to retrieve the delta time (deltaTime) for the current frame of the game. Delta time is often used to adjust game physics or animations to ensure smooth and frame-independent behavior.
Functions
getDeltaTime(): number
This function retrieves the current deltaTime from the game instance. If there is an error in fetching the deltaTime (for example, if the game instance is not properly initialized), the function will catch the error and return 0 as the default value.
Returns:
number: ThedeltaTimevalue (time in seconds since the last frame). If the value cannot be retrieved, it returns0.
Example Usage:
import { getDeltaTime } from "./delta-time-utils";
const deltaTime = getDeltaTime();console.log(deltaTime); // Logs the current deltaTime of the game.Error Handling:
- If the
Game.getInstance()method fails or ifdeltaTimeis not accessible, an error will be logged to the console and0will be returned as a fallback value.