Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/numeric.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tick_intervalObject

Returns the game tick interval. By default the tick interval is 16.66666.

Returns:

  • the game tick interval. By default the tick interval is 16.66666



14
15
16
# File 'lib/core_ext/numeric.rb', line 14

def self.tick_interval
  @tick_interval.to_f == 0 ? 16.666666 : @tick_interval.to_f
end

.tick_interval=(value) ⇒ Object

Set the tick interval which is used in conversion of seconds to ticks.



7
8
9
# File 'lib/core_ext/numeric.rb', line 7

def self.tick_interval=(value)
  @tick_interval = value.to_f
end

Instance Method Details

#secondObject Also known as: seconds, secs, sec

Provides the suffix ‘second’ which will translate seconds to game ticks. This is to allow for a number of seconds to be expressed in situations where game ticks are used (e.g. animations).

Examples:

Expressing an animation that takes place over 3 seconds (~180 ticks)


class ExampleScene < Metro::Scene
  draws :title

  animate :title, to: { x: 320, y: 444 }, interval: 3.seconds
end


33
34
35
# File 'lib/core_ext/numeric.rb', line 33

def second
  (self * 1000 / Numeric.tick_interval).floor
end

#tickObject Also known as: ticks

Provides the suffix ‘tick’ which will simply express the number with a vanity suffix.

Examples:

Expressing an animation that takes place over 60 game ticks


class ExampleScene < Metro::Scene
  draws :title

  animate :title, to: { x: 320, y: 444 }, interval: 60.ticks
end


53
54
55
# File 'lib/core_ext/numeric.rb', line 53

def tick
  self
end