Class: Chronus::Timer
- Inherits:
-
Object
- Object
- Chronus::Timer
- Defined in:
- lib/chronus/timer.rb
Instance Method Summary collapse
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
-
#pause ⇒ Object
Pause counter timer.
-
#paused? ⇒ Boolean
Return true if paused == true.
-
#resume ⇒ Object
Resume counter timer.
-
#start ⇒ Object
Start counter timer.
-
#started? ⇒ Boolean
Return true if started == true.
-
#stop ⇒ Object
Stop counter timer.
-
#ticks ⇒ Object
Return current tick.
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
6 7 8 9 10 11 |
# File 'lib/chronus/timer.rb', line 6 def initialize @start_ticks = 0 @paused_ticks = 0 @paused = false @started = false end |
Instance Method Details
#pause ⇒ Object
Pause counter timer
27 28 29 30 31 32 |
# File 'lib/chronus/timer.rb', line 27 def pause if @started == true && @paused == false @paused = true @paused_ticks = SDL.get_ticks - @start_ticks end end |
#paused? ⇒ Boolean
Return true if paused == true
62 63 64 |
# File 'lib/chronus/timer.rb', line 62 def paused? @paused end |
#resume ⇒ Object
Resume counter timer
35 36 37 38 39 40 41 |
# File 'lib/chronus/timer.rb', line 35 def resume if @paused == true @paused = false @start_ticks = SDL.get_ticks - @paused_ticks @paused_ticks = 0 end end |
#start ⇒ Object
Start counter timer
14 15 16 17 18 |
# File 'lib/chronus/timer.rb', line 14 def start @started = true @paused = false @start_ticks = SDL.get_ticks end |
#started? ⇒ Boolean
Return true if started == true
57 58 59 |
# File 'lib/chronus/timer.rb', line 57 def started? @started end |
#stop ⇒ Object
Stop counter timer
21 22 23 24 |
# File 'lib/chronus/timer.rb', line 21 def stop @started = false @paused = false end |
#ticks ⇒ Object
Return current tick
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/chronus/timer.rb', line 44 def ticks t = 0 if @started == true if @paused == true t = @paused_ticks else t = SDL.get_ticks - @start_ticks end end t end |