class AdventureRL::Deltatime

Constants

DELTATIMES

This Array is filled with all initialized Deltatime instances. The point of it is, that they are all reset once the Window opens ( Window#show ).

Public Class Methods

new() click to toggle source
# File lib/AdventureRL/Deltatime.rb, line 7
def initialize
  @last_update_at = nil
  @deltatime      = nil
  set_last_update_at
  set_deltatime
  DELTATIMES << self
end

Public Instance Methods

dt()
Alias for: get_deltatime
get()
Alias for: get_deltatime
get_deltatime() click to toggle source

Returns the value of the last calculated deltatime.

# File lib/AdventureRL/Deltatime.rb, line 16
def get_deltatime
  return @deltatime
end
Also aliased as: get, dt
reset() click to toggle source

Resets last updated deltatime. Used when wanting to pause this deltatime's calculations, so when resumed, deltatime isn't a large number.

# File lib/AdventureRL/Deltatime.rb, line 32
def reset
  set_last_update_at
end
update() click to toggle source

Call this method every tick / frame to update the deltatime value.

# File lib/AdventureRL/Deltatime.rb, line 24
def update
  set_deltatime
  set_last_update_at
end

Private Instance Methods

get_elapsed_seconds() click to toggle source
# File lib/AdventureRL/Deltatime.rb, line 47
def get_elapsed_seconds
  return Gosu.milliseconds.to_f / 1000.0
end
set_deltatime() click to toggle source
# File lib/AdventureRL/Deltatime.rb, line 38
def set_deltatime
  diff_in_secs = get_elapsed_seconds - @last_update_at
  @deltatime = diff_in_secs
end
set_last_update_at() click to toggle source
# File lib/AdventureRL/Deltatime.rb, line 43
def set_last_update_at
  @last_update_at = get_elapsed_seconds
end