struct

Termisu::Event::Tick

Inherits Struct / Value / Object

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/backpressure drops
      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

Constructors

new(elapsed : Time::Span, delta : Time::Span, frame : UInt64, missed_ticks : UInt64 = 0_u64)
Source

Instance methods

delta

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

Source
elapsed

Total time elapsed since the timer was started.

Source
frame

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

Source
missed_ticks

Number of missed timer ticks since last event. Non-zero indicates frame drops or backpressure drops. SystemTimer reports kernel-level missed expirations and also channel-backpressure drops. Sleep-based Timer reports channel-backpressure drops.

Source