Class: CyberarmEngine::Timer
- Inherits:
-
Object
- Object
- CyberarmEngine::Timer
- Defined in:
- lib/cyberarm_engine/timer.rb
Instance Method Summary collapse
-
#initialize(interval, looping = true, &block) ⇒ Timer
constructor
A new instance of Timer.
- #update ⇒ Object
Constructor Details
#initialize(interval, looping = true, &block) ⇒ Timer
Returns a new instance of Timer.
3 4 5 6 7 8 9 10 |
# File 'lib/cyberarm_engine/timer.rb', line 3 def initialize(interval, looping = true, &block) @interval = interval @looping = looping @block = block @last_interval = Gosu.milliseconds @triggered = false end |
Instance Method Details
#update ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cyberarm_engine/timer.rb', line 12 def update return if !@looping && @triggered if Gosu.milliseconds >= @last_interval + @interval @last_interval = Gosu.milliseconds @triggered = true @block.call if @block end end |