Class: CyberarmEngine::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberarm_engine/timer.rb

Instance Method Summary collapse

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

#updateObject



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