Skip to content

Keyframe

Syyrion edited this page Feb 19, 2022 · 1 revision

On the subject of keyframing and events.

The Keyframe class can do everything that sliders and timers can at the cost of more overhead. This class handles a timeline that can control and interpolate values as well as run functions. This is safer than using the game's included eval functions as it doesn't use string comprehension and won't crash upon an error.

Events

The Keyframe class processes events in a timeline. An event consists of a duration (referred to as period), value, function, easing function, timescale, and saved arguments. These parameters are unique to each event.

The duration is the amount of time it takes for the event to complete. During this time, the value of the Keyframe class will interpolate from the previous event's value to the current event's value. The easing function modifies this interpolation behavior. Once the event concludes, the event's function is run with any saved arguments are passed to it.

The Principle Event

Every Keyframe always stores a principle event which it uses as a reference. Whenever a new event is created, any values that aren't specified fall back to the principle event.

Functions

  • Keyframe:new(period, value, fn, easing, timescale)
    Creates a new Keyframe class with a principle event with period <period>, value <value>, function <function>, easing function <easing> and timescale <timescale>. The principle event cannot save arguments.

  • Keyframe:setPeriod(period)
    Sets the principle event's period in seconds

  • Keyframe:getPeriod()
    Gets the principle event's period.

  • Keyframe:setEaseFunction(easing)
    Sets the principle event's easing function.

  • Keyframe:getEaseFunction()
    Gets the principle event's easing function.

  • Keyframe:setTimescale(timescale)
    Sets the principle event's timescale.

  • Keyframe:getTimescale()
    Gets the principle event's timescale.

  • Keyframe:setFunction(fn)
    Sets the principle event's function.

  • Keyframe:getFunction()
    Gets the principle event's function.

  • Keyframe:setValue(x)
    Sets the Keyframe value. Mostly useless as the step function takes care of setting this value.

  • Keyframe:getValue()
    Gets the Keyframe value.

  • Keyframe:event(period, value, fn, easing, timescale, ...)
    Creates a new event. Any arguments passed to the variadic (...) are saved as arguments to be used when the event's function is run.

  • Keyframe:eval(period, fn, ...)
    A macro function for Keyframe:event(). Creates a new function event.

  • Keyframe:node(period, value, easing)
    A macro function for Keyframe:event(). Creates a new keyframe event.

  • Keyframe:sequence(...)
    Creates events in bulk. Accepts a tuple of tables. Each table should be a list of arguments to Keyframe:event() i.e. {period, value, fn, easing, timescale, ...}

  • Keyframe:absolute(...)
    Similar to sequence but periods are replaced with absolute timestamps.

  • Keyframe:isRunning()
    Returns true if the Keyframe is currently processing events.

  • Keyframe:clear()
    Clears all events. The Keyframe value remains at its current position.

  • Keyframe:step(mFrameTime)
    Processes events.

Clone this wiki locally