Sha256: 02215892f451dd7bfc1396548e051a503245a1023c8a8cb0ddeb02a2a8a6762a

Contents?: true

Size: 479 Bytes

Versions: 6

Compression:

Stored size: 479 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

6 entries across 6 versions & 1 rubygems

Version Path
cyberarm_engine-0.19.0 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.18.0 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.17.1 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.17.0 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.16.0 lib/cyberarm_engine/timer.rb
cyberarm_engine-0.15.0 lib/cyberarm_engine/timer.rb