Sha256: 177746a3c13cafe83268c6bbb5bb4eb78ad222766222f7f576a66be768829409

Contents?: true

Size: 502 Bytes

Versions: 10

Compression:

Stored size: 502 Bytes

Contents

module CyberarmEngine
  class Timer
    def initialize(interval, looping = true, &block)
      @interval = interval
      @looping = looping
      @block = block

      @last_interval = Gosu.milliseconds
      @triggered = false
    end

    def update
      return if !@looping && @triggered

      if Gosu.milliseconds >= @last_interval + @interval
        @last_interval = Gosu.milliseconds
        @triggered = true

        @block.call if @block
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cyberarm_engine-0.24.4 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.24.3 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.24.2 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.24.1 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.24.0 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.23.0 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.22.0 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.21.0 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.20.0 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.19.1 lib/cyberarm_engine/timer.rb