Skip to main content

Sizetweener

Overview

The SizeTweener component handles animated scaling of an entity’s transform over time. It supports starting and ending size tweens via linear interpolation (Lerp), optionally triggering a user-defined callback upon completion. It integrates with the entity’s update loop to perform per-frame interpolation when a tween is active.

Dependencies & Tags

  • Component Dependency: Transform (must be present on the entity; used via inst.Transform for scale manipulation)
  • Events Pushed: "sizetweener_start" and "sizetweener_end" (see Events & Listeners section)

No additional components are added or tags applied.

Properties

PropertyTypeDefault ValueDescription
instEntity(passed to constructor)The entity to which this component is attached
i_sizenumber?nilThe initial scale value at tween start (read from Transform:GetScale())
t_sizenumber?nilThe target scale value (uniform scale applied to X, Y, Z)
callbackfunction?nilOptional function to invoke when tween completes
timenumber?nilTotal duration (in seconds) of the tween
timepassednumber0Accumulated time elapsed during the current tween
tweeningbooleanfalseWhether a tween is currently in progress

Main Functions

StartTween(size, time, callback)

  • Description: Begins a size tween from the entity’s current scale to the specified size over time seconds. If time is 0 or negative, the tween ends immediately. Pushes the "sizetweener_start" event and starts updates if time > 0.
  • Parameters:
    • size (number): Uniform scale value to tween to (applied equally to X, Y, Z axes).
    • time (number): Duration of the tween in seconds. If ≤ 0, instant transition occurs.
    • callback (function?): Optional callback function accepting the entity (inst) as its sole argument, called when the tween completes.

EndTween()

  • Description: Stops the current tween (if active), snaps the entity’s scale to the target (t_size), resets internal state, pushes "sizetweener_end", and executes the callback if provided.
  • Parameters: None

OnUpdate(dt)

  • Description: Called each frame while tweening is active. Updates elapsed time and performs Lerp-based scaling. If the elapsed time reaches or exceeds the tween duration, triggers EndTween().
  • Parameters:
    • dt (number): Delta time in seconds since the last frame.

Events & Listeners

  • Events Pushed:
    • "sizetweener_start" — fired when a tween begins.
    • "sizetweener_end" — fired when a tween completes (either naturally or via EndTween()).
  • Event Listeners: None (this component does not listen for external events).