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}"

      # Check for missed frames (SystemTimer only)
      if event.missed_ticks > 0
        puts "Warning: #{event.missed_ticks} frame(s) dropped"
      end
    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, missed_ticks : UInt64 = 0_u64) #

[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]
def missed_ticks : UInt64 #

Number of missed timer ticks since last event. Non-zero indicates frame drops. Only available with SystemTimer; sleep-based Timer always reports 0.


[View source]