class SFML::Clock
Monotonic high-resolution timer. Wraps sfClock from CSFML.
clock = SFML::Clock.new # β¦ do work β¦ puts clock.elapsed_time.as_seconds clock.restart # returns the elapsed time and resets to zero
Public Class Methods
Source
# File lib/sfml/system/clock.rb, line 10 def initialize ptr = C::System.sfClock_create raise Error, "sfClock_create returned NULL" if ptr.null? @handle = FFI::AutoPointer.new(ptr, C::System.method(:sfClock_destroy)) end
Create a fresh clock β starts running at zero.
Public Instance Methods
Source
# File lib/sfml/system/clock.rb, line 18 def elapsed_time Time.from_native(C::System.sfClock_getElapsedTime(@handle)) end
Time elapsed since the clock was last started / restarted, as a SFML::Time. Aliased as elapsed.
Also aliased as: elapsed
Source
# File lib/sfml/system/clock.rb, line 48 def reset Time.from_native(C::System.sfClock_reset(@handle)) end
Reset to zero without affecting the running state. Returns the elapsed time before the reset.
Source
# File lib/sfml/system/clock.rb, line 42 def restart Time.from_native(C::System.sfClock_restart(@handle)) end
Atomic βread elapsed + reset to zeroβ. Standard pattern for per-frame dt: dt = clock.restart.
Source
# File lib/sfml/system/clock.rb, line 24 def running? C::System.sfClock_isRunning(@handle) end
true if the clock is currently ticking (not paused via stop).
Source
# File lib/sfml/system/clock.rb, line 29 def start C::System.sfClock_start(@handle) self end
Resume after stop. No-op if already running.
Source
# File lib/sfml/system/clock.rb, line 35 def stop C::System.sfClock_stop(@handle) self end
Pause the clock β elapsed_time freezes until start.