Class: SFML::Clock
- Inherits:
-
Object
- Object
- SFML::Clock
- Defined in:
- lib/sfml/system/clock.rb
Overview
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#elapsed_time ⇒ Object
(also: #elapsed)
Time elapsed since the clock was last started / restarted, as a
SFML::Time. -
#initialize ⇒ Clock
constructor
Create a fresh clock — starts running at zero.
-
#reset ⇒ Object
Reset to zero without affecting the running state.
-
#restart ⇒ Object
Atomic "read elapsed + reset to zero".
-
#running? ⇒ Boolean
trueif the clock is currently ticking (not paused via#stop). -
#start ⇒ Object
Resume after
#stop. -
#stop ⇒ Object
Pause the clock —
#elapsed_timefreezes until#start.
Constructor Details
#initialize ⇒ Clock
Create a fresh clock — starts running at zero.
10 11 12 13 14 |
# 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 |
Instance Attribute Details
#handle ⇒ Object (readonly)
:nodoc:
52 53 54 |
# File 'lib/sfml/system/clock.rb', line 52 def handle @handle end |
Instance Method Details
#elapsed_time ⇒ Object Also known as: elapsed
Time elapsed since the clock was last started / restarted, as a
SFML::Time. Aliased as #elapsed.
18 19 20 |
# File 'lib/sfml/system/clock.rb', line 18 def elapsed_time Time.from_native(C::System.sfClock_getElapsedTime(@handle)) end |
#reset ⇒ Object
Reset to zero without affecting the running state. Returns the elapsed time before the reset.
48 49 50 |
# File 'lib/sfml/system/clock.rb', line 48 def reset Time.from_native(C::System.sfClock_reset(@handle)) end |
#restart ⇒ Object
Atomic "read elapsed + reset to zero". Standard pattern for
per-frame dt: dt = clock.restart.
42 43 44 |
# File 'lib/sfml/system/clock.rb', line 42 def restart Time.from_native(C::System.sfClock_restart(@handle)) end |
#running? ⇒ Boolean
true if the clock is currently ticking (not paused via #stop).
24 25 26 |
# File 'lib/sfml/system/clock.rb', line 24 def running? C::System.sfClock_isRunning(@handle) end |