Class: Yeah::Ticker

Inherits:
Object
  • Object
show all
Defined in:
lib/yeah/_platform/ticker.rb

Overview

Note:

Provided by a Platform.

The Ticker provides a way to start a game loop.

Examples:

Print elapsed time between each tick

Ticker.new.on_tick { |elapsed| puts elapsed }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Ticker

Returns a new instance of Ticker

Parameters:

  • options (Hash) (defaults to: {})

    for new object

Options Hash (options):

  • :rate (Numeric) — default: 60

    at ticks per second

Raises:

  • (NotImplementedError)

10
11
12
# File 'lib/yeah/_platform/ticker.rb', line 10

def initialize(options = {})
  raise NotImplementedError
end

Instance Attribute Details

#rateInteger

Returns expected tick rate

Parameters:

  • ticks (Integer)

    per second

Returns:

  • (Integer)

    expected tick rate


# File 'lib/yeah/_platform/ticker.rb', line 14

#tick_countInteger (readonly)

Returns total count of ticks

Returns:

  • (Integer)

    total count of ticks


# File 'lib/yeah/_platform/ticker.rb', line 21

#ticks_per_secondInteger (readonly)

Returns ticks counted over the last second

Returns:

  • (Integer)

    ticks counted over the last second


# File 'lib/yeah/_platform/ticker.rb', line 18

Instance Method Details

#on_tick {|elapsed| ... } ⇒ Object

Yields:

  • (elapsed)

    block to execute per tick

Yield Parameters:

  • elapsed (Numeric)

    time since last tick


# File 'lib/yeah/_platform/ticker.rb', line 24