Fader
Overview
The Fader component enables smooth interpolation (fade-in/fade-out) of numeric values over time. It maintains a list of active fade operations, each defined by a start value, end value, duration, and a setter function to apply the interpolated value. It automatically starts/stops its own update loop based on active fades.
Dependencies & Tags
- Relies on
inst:StartUpdatingComponent(self)andinst:StopUpdatingComponent(self)to integrate with the entity’s update loop. - No components are added or tags assigned by this script.
- No other components are directly required or referenced.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | — | The entity the component is attached to. |
values | table | {} | List of active fade operations (each a table of fade parameters). |
numvals | number | 0 | Count of currently active fades. |
Main Functions
Fade(startval, endval, time, setter, atend, id)
- Description: Adds a new fade operation to the queue. Interpolates the value from
startvaltoendvalovertimeseconds using linear interpolation. Thesetterfunction is called each frame with(current_value, inst)to apply the interpolated value. Optionally executesatendwhen the fade completes. - Parameters:
startval(number): Starting value for the fade.endval(number): Target value at the end of the fade.time(number): Duration of the fade in seconds.setter(function): Callback(value, inst)invoked each frame to apply the current interpolated value.atend(function, optional): Callback(inst, value)invoked once when the fade finishes.id(number/string, optional): Identifier for the fade; defaults to its 1-based index invalues.
StopAll()
- Description: Immediately completes all active fades (by fast-forwarding their remaining time), clears the fade queue, and stops the component’s update loop.
- Parameters: None.
OnUpdate(dt)
- Description: Internal callback invoked each frame. Updates all active fades by decrementing remaining time, computing the interpolated value, and invoking the
setter. Completes and removes any fades whose time has elapsed (and triggersatendif present). - Parameters:
dt(number): Delta time in seconds since the last frame.
Events & Listeners
- Listens to: none (
inst:ListenForEventnot used). - Emits: none (
inst:PushEventnot used). - Updates itself via the entity’s update loop (
StartUpdatingComponent/StopUpdatingComponent), which is standard for DST components but not classified as a game event.