Console::Tween
console 0.2.0 · app/console/tween.rb · 270 lines · view source
Also defined here:
Console::TweenHost
Console::Tween -- frame-driven interpolation and a tick scheduler.
Tweening removes the "remember the start value, then lerp every frame" boilerplate that otherwise shows up in every prototype.
tween(entity, :x, to: 400, in: 30) # linear over 30 ticks tween(entity, :alpha, to: 0, in: 30, ease: :out) tween(entity, :y, from: 100, to: 0, in: 60, delay: 20) tween(entity, :w, to: 64, in: 20, on_done: -> { sfx :land })
The scheduler handles deferred work, the other half of prototype ergonomics:
after 30 { spawn Enemy, x: 100, y: 100 } # in half a second every 60, immediate: true { next_wave }
def initialize(target, property, options)- line 58
def capture!-
Lock in the value we are tweening away from.
def from_value-
The value this pass starts from.
def to_value- line 89
def done?- line 93
def progress(now = Kernel.tick_count)- line 97
def update(now = Kernel.tick_count)-
Advance to
now(defaults to the current tick). Returns true while the tween is still running. Passing an explicit tick makes tweens testable without sleeping through real frames. def apply(a, b, t, p)- line 143
def initialize- line 160
def tick_count- line 166
tweening
def tween(target, property, options = {})-
Tween one property of a Hash-like target. Returns the Tween so callers can cancel or inspect it.
def tween_all(target, properties, options = {})-
Tween several properties of one target with identical timing.
def cancel_tweens(target, property = nil)- line 190
def cancel_tween(tween)- line 197
def tweening?(target)- line 201
scheduling
def after(ticks, &block)-
Run a block once,
ticksframes from now. Returns a handle you can pass to cancel_timer. def every(ticks, options = {}, &block)-
Run a block on a fixed cadence.
immediate: truealso runs it now. def next_tick(&block)-
Run a block once, on the next frame.
def cancel_timer(entry)- line 231
def cancel_ticker(entry)- line 235
def pending_timers- line 239
frame
def update-
Advance everything. Timers fire before tickers, which fire before tweens, so a timer that starts a tween behaves predictably.
def clear- line 264