Tween

January 7, 2026 ยท View on GitHub

GMR Docs > Engine > Animation > Tween

Tween

Value interpolation over time with easing.

Table of Contents

Instance Methods

from(target, property, start_value, duration:, delay:, ease:)

Create a tween that animates a property TO a target value. The tween starts from the property's current value.

Parameters:

NameTypeDescription
targetObjectThe object to animate (must have property getter and setter)
propertySymbolThe property to animate (:x, :y, :alpha, :rotation, etc.)
end_valueFloatThe target value to animate to

Returns: Tween - The tween instance for chaining

Example:

# Smooth camera zoom for scope/aim mode
  def toggle_aim_mode

#from

Create a tween that animates a property FROM a start value to current. Useful for "animate in" effects like fading in from transparent.

Parameters:

NameTypeDescription
targetObjectThe object to animate
propertySymbolThe property to animate
start_valueFloatThe value to animate from

Returns: Tween - The tween instance for chaining

Example:

# Toast notification slides in from bottom
  class Toast
    def show(message)

#on_complete

Set a callback to invoke when the tween completes.

Returns: Tween - self for chaining

Example:

# Sequence of tweens using on_complete for chaining
  class Chest
    def open
      # First: lid opens
      GMR::Tween.to(@lid, :rotation, -1.5, duration: 0.3, ease: :out_quad)
        .on_complete do
          # Second: spawn item and make it rise

#on_update

Set a callback to invoke each frame during the tween. The callback receives (t, value) where t is normalized progress [0-1] and value is the current interpolated value.

Returns: Tween - self for chaining

Example:

# Color cycling effect on update
  def start_rainbow_effect

#cancel

Cancel the tween immediately. Does not invoke on_complete.

Returns: nil

Example:

# Cancel movement when player hits wall
  class Player
    def move_to(target_x, target_y)

#pause

Pause the tween. Use resume to continue.

Returns: Tween - self for chaining

Example:

# Pause all UI animations when game pauses
  class PauseMenu
    def show

#resume

Resume a paused tween.

Returns: Tween - self for chaining

Example:

tween.resume

#complete?

Check if the tween has finished.

Returns: Boolean - true if completed

Example:

if tween.complete?
  puts "Done!"
end

#active?

Check if the tween is currently running (not paused, cancelled, or complete).

Returns: Boolean - true if active

Example:

if tween.active?
  puts "Still animating..."
end

#paused?

Check if the tween is paused.

Returns: Boolean - true if paused


#progress

Get the current progress of the tween (0.0 to 1.0).

Returns: Float - Progress value


#cancel_all

Cancel all active tweens.

Returns: nil

Example:

# Clean slate when transitioning scenes
  class GameScene < GMR::Scene
    def unload
      # Cancel all tweens to prevent callbacks on destroyed objects
      GMR::Tween.cancel_all
      # Clean up resources

#count

Get the number of active tweens.

Returns: Integer - Number of active tweens

Example:

puts "Active tweens: #{GMR::Tween.count}"


Back to Animation | Documentation Home