class
Eagle::Tween
- Eagle::Tween
- Reference
- Object
Overview
Animates a value over time, so you don't have to track timers yourself.
A tween calls your block every frame with progress eased from 0 to 1, or with an
interpolated value, until its duration is up. The engine updates tweens automatically,
and they follow Clock.scale.
class Popup < Node2D
def ready : Nil
self.scale = 0.0
# Grow in with a springy overshoot.
Tween.value(0, 1, 0.4, ease: :back_out) { |s| self.scale = s }
# Fade out after 2 seconds, then remove.
Tween.value(Color::WHITE, Color::TRANSPARENT, 0.5, delay: 2) { |c| self.modulate = c }
.on_complete { queue_free }
end
end
# Run steps one after another.
Tween.sequence do |s|
s.wait(1)
s.to(0.5, ease: :quad_out) { |t| puts "sliding #{t}" }
s.call { puts "done" }
end
Tween.after(3) { puts "three seconds later" }
Keep the returned Tween if you need to #stop it early, or set loop or ping_pong
for animations that repeat.
Defined in:
eagle/core/tween.crConstructors
-
.after(seconds : Number, &block : -> ) : Tween
Calls the block once after seconds.
-
.new(duration : Number, ease : Symbol | Proc(Float32, Float32) = :linear, delay : Number = 0, &block : Float32 -> )
Creates a tween without starting it.
-
.to(duration : Number, ease : Symbol | Proc(Float32, Float32) = :linear, delay : Number = 0, &block : Float32 -> ) : Tween
Starts a tween whose block receives eased progress from 0 to 1.
-
.value(from : Number, to : Number, duration : Number, ease : Symbol = :linear, delay : Number = 0, &block : Float32 -> ) : Tween
Tweens a number from from to to and passes each value to the block.
-
.value(from : Vec2, to : Vec2, duration : Number, ease : Symbol = :linear, delay : Number = 0, &block : Vec2 -> ) : Tween
Tweens a
Vec2, for moving things between two points. -
.value(from : Vec3, to : Vec3, duration : Number, ease : Symbol = :linear, delay : Number = 0, &block : Vec3 -> ) : Tween
Tweens a
Vec3. -
.value(from : Color, to : Color, duration : Number, ease : Symbol = :linear, delay : Number = 0, &block : Color -> ) : Tween
Tweens a
Color, for fades and flashes.
Class Method Summary
-
.active_count : Int32
Number of tweens currently running.
-
.clear : Nil
Stops every running tween, for example when changing scenes.
-
.sequence(&) : Sequence
Builds a chain of steps with the yielded
Sequenceand starts it.
Instance Method Summary
-
#delay : Float32
Seconds to wait before starting.
-
#delay=(delay : Float32)
Seconds to wait before starting.
-
#duration : Float32
Length of the tween in seconds, not counting
#delay. -
#elapsed : Float32
Seconds played so far.
-
#finished? : Bool
True once the tween has reached the end and called its completion blocks.
-
#loop=(loop : Bool)
Restarts from the beginning when it finishes, forever.
-
#loop? : Bool
Restarts from the beginning when it finishes, forever.
-
#on_complete(&block : -> ) : self
Adds a block to run when the tween finishes.
-
#paused=(paused : Bool)
Freezes the tween in place while true.
-
#paused? : Bool
Freezes the tween in place while true.
-
#ping_pong=(ping_pong : Bool)
With
loop, plays forward then backward alternately. -
#ping_pong? : Bool
With
loop, plays forward then backward alternately. -
#progress : Float32
Linear progress from 0 to 1, before easing.
-
#start : self
Starts or resumes updating this tween.
-
#stop : Nil
Removes the tween from the update list.
Constructor Detail
Calls the block once after seconds. A timer without a node.
Creates a tween without starting it. Call #start when ready, or use Tween.to,
which creates and starts in one step.
Starts a tween whose block receives eased progress from 0 to 1. Use it to drive any property you like.
start, target = v2(0, 0), v2(300, 200)
node = Node2D.new
Tween.to(1.5, ease: :sine_in_out) { |t| node.position = start.lerp(target, t) }
Tweens a number from from to to and passes each value to the block.
Tweens a Vec2, for moving things between two points.
Tweens a Vec3.
Tweens a Color, for fades and flashes.
Class Method Detail
Instance Method Detail
Adds a block to run when the tween finishes. Returns self so calls can be chained.