struct Termisu::Event::Tick

Overview

Timer tick event.

Generated at regular intervals when the timer is enabled. Provides timing information for animations and game loops.

Example:

termisu.enable_timer(16.milliseconds) # ~60 FPS

loop do
  if event = termisu.poll_event(100)
    case event
    when Termisu::Event::Tick
      # Use delta for frame-rate independent animations
      position += velocity * event.delta.total_seconds
      puts "Frame #{event.frame}, elapsed: #{event.elapsed}"
    when Termisu::Event::Key
      break if event.key.escape?
    end
  end
  termisu.render
end

Defined in:

termisu/event/tick.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(elapsed : Time::Span, delta : Time::Span, frame : UInt64) #

[View source]

Instance Method Detail

def delta : Time::Span #

Time since the previous tick event. Useful for frame-rate independent animations.


[View source]
def elapsed : Time::Span #

Total time elapsed since the timer was started.


[View source]
def frame : UInt64 #

Frame counter (starts at 0, increments each tick).


[View source]