MODULE v1.8.0

time

pykraken.time

Time related functions

Reference

PYTHON API

delay

function
delay(milliseconds: int) -> None

Delay the program execution for the specified duration.

This function pauses execution for the given number of milliseconds. Useful for simple timing control, though using time.set_cap() is generally preferred for precise frame rate control with nanosecond accuracy.

Args

  • milliseconds (int) — The number of milliseconds to delay.

get_delta

function
get_delta() -> float

Get the time elapsed since the last frame in seconds.

For stability, the returned delta is clamped so it will not be smaller than 1/12 seconds (equivalent to capping at 12 FPS). This prevents unstable calculations that rely on delta when very small frame times are measured.

Returns

  • float — The time elapsed since the last frame, in seconds.

get_elapsed

function
get_elapsed() -> float

Get the elapsed time since the program started.

Returns

  • float — The total elapsed time since program start, in seconds.

get_fps

function
get_fps() -> float

Get the current frames per second of the program.

Returns

  • float — The current FPS based on the last frame time.

get_scale

function
get_scale() -> float

Get the current global time scale factor.

Returns

  • float — The current time scale factor.
set_max_delta(max_delta: float) -> None

Set the maximum allowed delta time between frames.

Args

  • max_delta (float) — Maximum delta time in seconds (> 0.0). Use this to avoid large deltas during frame drops or pauses that could destabilize physics or animations.

set_scale

function
set_scale(scale: float) -> None

Set the global time scale factor.

Args

  • scale (float) — The time scale factor. Values < 0.0 are clamped to 0.0. A scale of 1.0 represents normal time, 0.5 is half speed, and 2.0 is double speed.

set_target

function
set_target(frame_rate: int) -> None

Set the target framerate for the application.

Args

  • frame_rate (int) — Target framerate to enforce. Values <= 0 disable frame rate limiting.

Find your next step

Start typing to search the manual.