module
Eagle::Clock
Overview
Frame timing you can read from anywhere: how long the last frame took, how long the game has been running, the frame rate, and a global time scale.
The dt passed to App#update and Node#process is the same as Clock.delta.
Multiply speeds by it so movement is the same at any frame rate.
.scale slows down or speeds up everything that uses .delta: set it to 0.3 for
slow motion or 0 to freeze gameplay while menus keep working through .raw_delta.
class Hud < Node2D
def draw(g : Graphics) : Nil
g.print("fps #{Clock.fps.round} t=#{Clock.elapsed.round(1)}s", 10, 10)
end
end
Clock.scale = 0.25 # bullet time
pulse = Math.sin(Clock.elapsed * 4) # a value that oscillates over time
Defined in:
eagle/core/clock.crClass Method Summary
-
.delta : Float32
Seconds since the last frame, multiplied by
.scale. -
.elapsed : Float64
Real seconds since the engine started.
-
.fixed_alpha : Float32
How far the current frame sits between the last fixed step and the next, from 0 to 1.
-
.fixed_delta : Float32
Length of one fixed step in seconds, which is
1 / Config#fixed_fps. -
.fixed_delta=(v : Number)
Changes the fixed step length.
-
.fps : Float32
Measured frames per second, updated twice a second.
-
.frame : Int64
Number of frames since start.
-
.max_delta=(v : Number)
Largest
.deltaa single frame can report, 0.25 s by default. -
.raw_delta : Float32
Seconds since the last frame, ignoring
.scale. -
.scale : Float32
Time scale applied to
.delta: 1 is normal, 0.5 is half speed and 0 pauses gameplay. -
.scale=(v : Number)
Sets the time scale.
Class Method Detail
Seconds since the last frame, multiplied by .scale. Clamped so a long hitch
(for example after a breakpoint) doesn't teleport everything.
Real seconds since the engine started. Handy for animations driven by Math.sin.
How far the current frame sits between the last fixed step and the next, from 0 to 1. Use it to interpolate positions of physics objects for smooth rendering at high refresh rates.
Length of one fixed step in seconds, which is 1 / Config#fixed_fps.
Largest .delta a single frame can report, 0.25 s by default. This stops a long
stall from causing a burst of physics steps.
Seconds since the last frame, ignoring .scale. Use it for UI and menus that must keep
moving while the game is paused or slowed down.