Class: RichEngine::Timer
- Inherits:
-
Object
- Object
- RichEngine::Timer
- Defined in:
- lib/rich_engine/timer.rb,
lib/rich_engine/timer/every.rb
Overview
Accumulates elapsed time; drive it by calling #update each frame.
Defined Under Namespace
Classes: Every
Class Method Summary collapse
-
.every(seconds: 1, &block) ⇒ RichEngine::Timer::Every
Returns a small scheduler that fires a block at a fixed interval.
Instance Method Summary collapse
-
#get ⇒ Float
The accumulated time in seconds.
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
-
#reset! ⇒ Integer
Resets the accumulated time back to zero.
-
#update(dt) ⇒ Float
Adds the elapsed time to the accumulated total.
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
18 19 20 |
# File 'lib/rich_engine/timer.rb', line 18 def initialize @timer = 0 end |
Class Method Details
.every(seconds: 1, &block) ⇒ RichEngine::Timer::Every
Returns a small scheduler that fires a block at a fixed interval.
14 15 16 |
# File 'lib/rich_engine/timer.rb', line 14 def self.every(seconds: 1, &block) Every.new(seconds) end |
Instance Method Details
#get ⇒ Float
Returns the accumulated time in seconds.
31 32 33 |
# File 'lib/rich_engine/timer.rb', line 31 def get @timer end |
#reset! ⇒ Integer
Resets the accumulated time back to zero.
38 39 40 |
# File 'lib/rich_engine/timer.rb', line 38 def reset! @timer = 0 end |
#update(dt) ⇒ Float
Adds the elapsed time to the accumulated total.
26 27 28 |
# File 'lib/rich_engine/timer.rb', line 26 def update(dt) @timer += dt end |