Discord

Preparing your files

Please wait until the download is ready.

Luka's Scripting Utilities

Luka's Scripting Utilities

by Luka S.J.

A pack full of various scripting utilities to ease your development!

v4.1.135,194
Download144 KB

Animatable

LUTS::Concerns::Animatable lets you tween any numeric property of an object
towards a target value. It is already included in Sprite, Viewport,
Color, Tone and Rect, so you can animate those directly. To make your own
class animatable, include LUTS::Concerns::Animatable.

How it works

You register the target values you want with animate, then let
Graphics.animate drive the tween over a number of frames. The
object is queued in Graphics.target_object_cache and each registered property
is advanced every frame (using frame-rate-independent lerp interpolation)
until the duration elapses.

Graphics.animate(30) do          # tween over 30 frames
  @sprite.animate(x: 400, y: 120, opacity: 0)
end

API

  • object.animate(options) registers properties → target values to tween (a Hash like { x: 400, opacity: 0 }). Ignored if the object is already animating.
  • object.animating? whether any animation targets are currently registered
  • object.anim_target the registered targets (each stored with its interpolation state)
  • object.play_target_animation(duration) advances every registered property one step towards its target over duration frames — normally called for you by Graphics.animate
  • object.clear_anim_target clears all registered animation values

QuickAnimatable

LUTS::QuickAnimatable is a higher-level, declarative layer for sprite-group
animations. Include it in a class that exposes sprites, viewport and
update, then describe the animation as an array of steps.

Each step is [duration, { sprite_key => { attribute => value } }]:

class MyScene
  include LUTS::QuickAnimatable

  def quick_animation_array
    [
      [20, { logo: { opacity: 255, y: 100 } }],
      [10, { logo: { zoom_x: 1.2, zoom_y: 1.2 } }]
    ]
  end
end
  • play_quick_animation plays every step in quick_animation_array in sequence, calling animate on the named sprites
  • quick_animation_array (you implement this) returns the list of animation steps; raises NotImplementedError if missing

The concern validates at runtime that the host class provides sprites,
viewport and update before playing.