Class: SFML::Clock

Inherits:
Object
  • Object
show all
Defined in:
lib/sfml/system/clock.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClock

Returns a new instance of Clock.

Raises:



9
10
11
12
13
# File 'lib/sfml/system/clock.rb', line 9

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

#handleObject (readonly)

:nodoc:



42
43
44
# File 'lib/sfml/system/clock.rb', line 42

def handle
  @handle
end

Instance Method Details

#elapsed_timeObject Also known as: elapsed



15
16
17
# File 'lib/sfml/system/clock.rb', line 15

def elapsed_time
  Time.from_native(C::System.sfClock_getElapsedTime(@handle))
end

#resetObject



38
39
40
# File 'lib/sfml/system/clock.rb', line 38

def reset
  Time.from_native(C::System.sfClock_reset(@handle))
end

#restartObject



34
35
36
# File 'lib/sfml/system/clock.rb', line 34

def restart
  Time.from_native(C::System.sfClock_restart(@handle))
end

#running?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/sfml/system/clock.rb', line 20

def running?
  C::System.sfClock_isRunning(@handle)
end

#startObject



24
25
26
27
# File 'lib/sfml/system/clock.rb', line 24

def start
  C::System.sfClock_start(@handle)
  self
end

#stopObject



29
30
31
32
# File 'lib/sfml/system/clock.rb', line 29

def stop
  C::System.sfClock_stop(@handle)
  self
end