pyxen.time
Access frame-based timing information from the engine.
See also: Game Loop.
time = pyxen.time
The time module provides:
- Current frame number
- Frames per second
- Delta time
- Elapsed time
All properties are read-only.
Properties
| Property | Type | Description |
|---|---|---|
frame | int | Current frame number since start |
fps | int | Target frames per second |
dt | float | Delta time (seconds per frame) |
t | float | Elapsed time in seconds |
frame
current_frame = pyxen.time.frame
- Starts at
0 - Increments every frame
- Useful for frame-based logic
Example:
if pyxen.time.frame % 60 == 0:
print("One second passed (at 60 FPS)")
fps
fps = pyxen.time.fps
Returns the engine’s frames per second.
Example:
print("Running at", pyxen.time.fps, "FPS")
dt (Delta Time)
delta = pyxen.time.dt
Equivalent to:
1.0 / pyxen.time.fps
Represents the duration of a single frame in seconds.
Useful for frame-rate independent movement:
player.x += speed * pyxen.time.dt
t (Elapsed Time)
elapsed = pyxen.time.t
Equivalent to:
pyxen.time.frame / pyxen.time.fps
Represents total time since the game started (in seconds).
Example:
if pyxen.time.t > 10:
spawn_boss()
Frame-Based vs Time-Based Logic
Frame-Based
if pyxen.time.frame % 30 == 0:
blink()
Predictable and deterministic.
Time-Based
player.x += velocity * pyxen.time.dt
Independent of FPS changes.
Common Patterns
Animation Timer
if pyxen.time.t % 1.0 < 0.5:
sprite.visible = True
else:
sprite.visible = False
Cooldown Timer
if pyxen.time.t - last_shot_time > 0.25:
shoot()
last_shot_time = pyxen.time.t
Delayed Action (Frame-Based)
if pyxen.time.frame == 120:
start_level()
Read-Only Safety
All properties are read-only:
pyxen.time.frame = 10 # ❌ Raises ValueError
The engine manages time state internally.
For more on the game loop, see Game Loop.