Transitions
onChange runs once when the state changes. onTransition runs repeatedly with a current value that moves from the previous state to the next one, and an alpha that shows the progress. This page covers how transitions behave and the settings that control them.
The examples on this page use a handler made from a rule for a button, like this:
const Vide = require("@packages/Vide")
const VideState = require("@VideState")
const schemas = VideState.schemas
const rules = VideState.rules
const ButtonRule = rules.dynamic(schemas.new({
transparency = schemas.float({ min = 0, max = 1 }),
offset = schemas.float(),
}), {
name = "Button",
allowedStateNames = { "Idle", "Hovered", "Pressed", "Disabled" },
})
const handler = ButtonRule.new({
Idle = { transparency = Vide.source(0), offset = Vide.source(0) },
Hovered = { transparency = Vide.source(0), offset = Vide.source(0.05) },
Pressed = { transparency = Vide.source(0.2), offset = Vide.source(0) },
Disabled = { transparency = Vide.source(0.6), offset = Vide.source(0) },
}, "Idle")Every onTransition connection has its own tween, so each one can animate with its own settings. Pass them as the second argument of onTransition, inside tweenDefault. A setting a connection leaves out takes the built-in default. A handler has no tween options of its own, so the settings belong to the connection that uses them.
-- `frame` is any Frame that the button draws.
local frame = Instance.new("Frame")
-- The fade is quick and eases out.
handler.onTransition(function(_, _, current)
frame.BackgroundTransparency = current.transparency
end, {
tweenDefault = {
duration = 0.2,
easing = "quadOut",
},
})
-- The slide is slower and overshoots a little.
handler.onTransition(function(_, _, current)
frame.Position = UDim2.fromScale(current.offset, 0)
end, {
tweenDefault = {
duration = 0.5,
easing = "backOut",
},
})animate is the same transition with Vide sources instead of a callback. It takes the same options, so everything on this page applies to it too. Use onTransition when you want to run your own code on each frame, and animate when you only need to bind the values to properties.
Connections with the same settings still start together and stay in step. Each connection costs its own set of tweens, so connect only the listeners that need to animate.
Strings cannot be transitioned
Only numbers, vectors and the other animatable types are tweened. A string field cannot be, so it does not change gradually. It switches to its next value at the start of the transition, and the same is true for booleans, enums, and any other value that is not animatable. For example, a label's text changes immediately while its transparency fades.
If you need a gradual effect on text, such as a typewriter reveal, build it yourself from alpha.
Behavior
- Each animatable field is tweened from its previous value to its next value.
- Fields that cannot be tweened, such as booleans, strings, and enums, switch to their next value at the start of the transition.
- A duration of
0calls the callback once withcurrentequal to the next value and analphaof1. setState(name, { instant = true })does the same for one change, whatever the duration is. SeesetState.- Calling
setStateagain before a transition finishes stops the earlier animation and starts a new one. The new one starts from the value the earlier animation had reached, socurrentdoes not jump. Thefromargument of the callback is still the previous state's values. - No animation runs while there are no
onTransitionlisteners, and a transition stops once every listener has disconnected. - A listener added during a transition receives updates from the next transition.
- Every easing starts at the previous value and ends at the next one.
backandelasticeasings overshoot, so numeric values can go below the start or above the end. Clamp them in your callback if your UI needs a fixed range.
Animatable fields
These types are tweened:
- Numbers and vectors, including
Vector2andVector3. CFrame,Color3,UDim,UDim2, andRect.NumberRange. Its minimum and its maximum are tweened separately.NumberSequenceandColorSequence, keypoint by keypoint. Both values need the same number of keypoints.- Tables whose values are numbers, vectors, or
Vector3s with the same keys.
These are not tweened. They switch to their next value at the start of the transition:
string,boolean,enum, andoptionalfields.- A
NumberSequenceorColorSequencewhose keypoint count changes. - Every other type.
A few things to know:
- An easing that overshoots, such as
back, can push the minimum of aNumberRangeabove its maximum. The range is clamped to keep the minimum at or below the maximum. - A sequence keeps its first keypoint at time
0and its last at1, and its other times stay in order. currentis not validated against the schema again. A tweenedintegerfield can hold a fractional value in the middle of a transition, so round it in your callback if you need a whole number.
alpha
alpha is the progress of the transition, from 0 at the start to 1 at the end. It follows the same easing and duration as the tweened fields, so it matches how far the transition has moved. Use it to drive values that cannot be tweened.
back and elastic easings overshoot. With them, alpha goes below 0 or above 1 during the transition and settles at exactly 1 when it ends. This is expected, because the same curve moves the tweened fields past their start or end. Clamp it with math.clamp(alpha, 0, 1) if you need a fixed range.
Overrides for state changes Added in 0.4.0
A connection can use other tween settings for particular state changes. A state change is the state the handler leaves and the state it enters. tweenOverrides is an array of entries, and each entry names those states and the settings to use for them:
handler.animate({
tweenDefault = {
duration = 0.15,
easing = "quadOut",
},
tweenOverrides = {
{
from = {
"Idle",
"Hovered",
},
to = {
"Pressed",
},
tween = {
duration = 0.05,
easing = "linear",
},
},
{
-- from is left out, so it means every state
to = {
"Disabled",
},
tween = {
duration = 0.5,
easing = "sineInOut",
},
},
},
})fromandtoare arrays of state names. A side that is left out means every state.tweentakes the same settings astweenDefault. A setting it leaves out keeps the one oftweenDefault.- A state change that no entry matches uses
tweenDefault. - To keep
tweenDefaultandtweenOverridesin one module that many components share, see Tween config. - At most one entry may match a state change, so the order of the array does not matter. An overlap raises an error when
onTransitionoranimateis called. The error lists every problem together: overlaps, a state the handler does not have, an empty array, an entry that leaves out both sides, an entry that only matches a state to itself, and an entry with notween. - The settings are picked when
setStatestarts the transition, once for each connection. A connection with no overrides does no extra work. A source inside the settings is still read every frame. - When a transition is interrupted, the entry is picked for the state the handler was heading to and the new state. The value still continues from where it is.
- The speed works as it does without overrides: the duration is divided by the speed of the connection, then by the global speed, as
(duration / localSpeed) / globalSpeed. - A different tween for one field is another connection. Call
animateoronTransitionagain with the settings that field needs.
Delays
A connection with a delay waits before its tween starts. Give each connection a larger delay to stagger them, such as list items that appear one after another:
-- `items` is a list of Frames, such as the rows of a list.
for index, item in items do
handler.onTransition(function(_, _, current)
item.BackgroundTransparency = current.transparency
end, {
tweenDefault = {
delay = (index - 1) * 0.05,
},
})
end- The connection sends nothing while it waits. A delay rarely ends exactly on a frame, so the first frame plays the part of that frame that comes after the delay. Staggered connections stay evenly spaced at any frame rate.
- The wait is scaled time:
pause, aspeedof0, andscaleSpeedapply to it too. setState(name, { instant = true })skips the delay, andfinishends a connection that is still waiting.- The transition finishes, and
onFinishruns, only after the most delayed connection ends.
Delaying a state change Added in 0.5.0
setState(name, { delay = seconds }) delays one state change. The state changes at once, so currentState and the events update, but every connection waits that long before its first frame, on top of its own delay.
Staggering handlers Added in 0.5.0
To stagger separate handlers, such as one handler per list item, pass stagger to everyHandler.setState. The handlers start one after another, in the order they were created:
const VideState = require("@VideState")
-- Every handler here comes from a rule named "ListItem" that has a "Shown" state, one handler for each row.
-- The first item starts at once, the second after 0.05 seconds, the third after 0.1 seconds, and so on.
VideState.everyHandler.withRule("ListItem").setState("Shown", { stagger = 0.05 })Each handler receives a delay of stagger × its position, added to any delay you pass. Create the handlers in the order they should appear.
Pausing
pause freezes every transition of a handler, and resume continues them from the same values. onPause and onResume report the os.clock() time at which the most recent transition started, so you can work out how long it has been running.
handler.onPause(function(startedAt)
print("paused after", os.clock() - startedAt, "seconds")
end)
handler.pause()
handler.resume()- A paused transition keeps its values and its listeners are not called again.
setStatewhile paused starts the new transition, sends its first frame, and holds it there untilresume.- Pausing applies to the whole handler. To pause or slow a single connection, use a
speedsource in that connection's options. Aspeedof0pauses only that connection and does not fireonPause. - If
speedis also0, the transition stays frozen afterresumeuntil the speed is above0.
Scaling the speed and finishing
scaleSpeed plays transitions faster or slower, and finish ends it at once. Use them to let a player skip an animation.
handler.onFinish(function(startedAt)
print("took", os.clock() - startedAt, "seconds")
end)
handler.scaleSpeed({ speed = 4, once = true })
handler.finish()scaleSpeedmultiplies each connection's ownspeed. By default it stays for every following transition, until you callscaleSpeedagain. Passonce = trueto apply it only to the transition that is running, so the nextsetStateplays at normal speed. To scale, pause, or finish every handler at once, useVideState.everyHandler.finishsends every connection its last frame, withcurrentequal to the next state's values and analphaof1, before it returns. It works while the handler is paused.onFinishruns once per transition, when the last connection that was playing it ends. A transition that a newersetStatereplaces does not finish.- Connections with different durations finish at different times, so the event waits for the slowest one.
waitForFinishyields until the handler has no running transition, for code that runs in sequence.
Tween settings presets Added in 0.6.0 Changed in 0.7.0
Tween settings are checked when a connection is made. To check a preset where you write it, for example in a shared config module, use tween.
tween Added in 0.6.0 Changed in 0.7.0
VideState.tween(settings: TweenSettings): TweenSettingsChecks settings and returns a frozen copy. It runs the same checks as tweenDefault, so a bad preset fails when the module loads instead of when a component connects. The result works anywhere tweenDefault does, and a plain table still works too.
const VideState = require("@VideState")
const Fast = VideState.tween({ duration = 0.15, easing = "quadOut" })
handler.animate({ tweenDefault = Fast })A source is checked once, with its current value, as it is for tweenDefault. The copy is frozen, so write a variant as a new tween call.
| Cause | Message | |
|---|---|---|
| Error | settings is not a table | tween expects a table, got <type> |
| Error | An unknown key or an invalid setting | The message of TweenSettings, such as onTransition duration must be a finite non-negative number |
Custom easing Added in 0.5.0
The built-in easings are names. For a curve of your own, make one and pass it as easing:
const VideState = require("@VideState")
handler.animate({
tweenDefault = {
duration = 0.3,
-- The same curve as CSS cubic-bezier(0.34, 1.56, 0.64, 1).
easing = VideState.bezier(0.34, 1.56, 0.64, 1),
},
})The functions below return a value that easing accepts in place of a name, including from a Vide source. A plain function does not work in easing, because a function there is read as a source. A table that was not made by these two is rejected.
bezier Added in 0.5.0
VideState.bezier(
x1: number, -- The horizontal position of the first control point
y1: number, -- The vertical position of the first control point
x2: number, -- The horizontal position of the second control point
y2: number -- The vertical position of the second control point
) -> CustomEasingMakes a cubic bezier easing, like CSS cubic-bezier, so a curve from a design tool works as it is. The curve starts at 0 and ends at 1.
Parameters
| Name | Type | Description |
|---|---|---|
x1 | number | Must be between 0 and 1. |
y1 | number | Any finite number. A value outside 0 to 1 overshoots like the back easings. |
x2 | number | Must be between 0 and 1. |
y2 | number | Any finite number. A value outside 0 to 1 overshoots like the back easings. |
Returns
| Type | Description |
|---|---|
CustomEasing | An easing for the easing setting. |
Errors
| Cause | Message | |
|---|---|---|
| Error | A number is not finite | bezier expects four finite numbers |
| Error | x1 or x2 is outside 0 to 1 | bezier x1 and x2 must be between 0 and 1 |
easing Added in 0.5.0
VideState.easing(
fn: (number) -> number -- Takes the progress from 0 to 1 and returns the eased progress
) -> CustomEasingWraps your own easing function:
const VideState = require("@VideState")
handler.animate({
tweenDefault = {
-- Starts slowly and speeds up, like the built-in "quadIn".
easing = VideState.easing(function(progress)
return progress * progress
end),
},
})The function is called with 0 and 1 when it is made, and it must return finite numbers for both. It should return 0 at 0 and 1 at 1, so a transition starts at the old value and ends at the new one. A later result that is not a finite number ends the transition with an error.
The function should depend only on the progress, so the same progress always gives the same result. VideState calls it for every handler on every frame, and does not reuse one handler's result for another, so a function that reads something else still works. The built-in easings, bezier, spring, and bounce are reused between handlers that are at the same progress, which makes a bulk state change cheaper.
Parameters
| Name | Type | Description |
|---|---|---|
fn | (number) -> number | The easing curve. It may overshoot. |
Returns
| Type | Description |
|---|---|
CustomEasing | An easing for the easing setting. |
Errors
| Cause | Message | |
|---|---|---|
| Error | fn is not a function | easing expects a function, got <type> |
| Error | fn does not return a finite number for 0 or 1 | easing must return a finite number for a progress of 0 and 1 |
| Error | During a transition, fn returns a value that is not a finite number | a custom easing returned a value that is not a finite number |
spring Added in 0.5.0
VideState.spring(
options: SpringOptions? -- The look of the bounces and when they happen
) -> CustomEasingMakes an easing in the shape of a spring: it starts at 0 without a jump, passes 1, comes back and passes it again, and has settled at 1 when the duration ends.
const VideState = require("@VideState")
handler.animate({
tweenDefault = {
duration = 0.5,
-- The first bounce goes 20% past the target, it bounces 3 times, and each bounce loses half its height.
easing = VideState.spring({ height = 0.2, bounces = 3, loss = 0.5 }),
},
})This is not a real spring
spring is a curve, like backOut or elasticOut, with a bounce you can adjust. It is not a physics simulation.
- It always takes the whole
duration. A real spring settles when its energy runs out. This curve is fitted to the duration you give, so the duration is also the time it takes to settle. - It does not keep the speed of an earlier transition. If
setStateinterrupts a transition, the new one starts from the current value with no speed, so a quick change of mind shows a small kink where a real spring would curve smoothly. - It does not react to how far the value travels. A short move and a long move wobble for the same time.
Use it for the look of a spring. If you need the behavior of one, VideState does not have it.
All the settings are optional and are set separately, and the curve always ends on the duration. Two groups of them:
What the bounces look like
heightis how far the first bounce passes the target, as a fraction of the distance.0.2goes 20% past it, so a value that moves from 0 to 100 reaches 120 before it comes back.bouncesis how many times it passes the target and comes back.lossis how much of its height each bounce loses. With0.5, each bounce is half as high as the one before, so bounces of 20%, 10%, and 5%. A lowlosskeeps the bounces tall, and a high one makes them die out fast.anticipationis a small dip backwards before it moves.0.1dips 10% of the distance below the start, and then it springs forward. The dip does not change how high the first bounce goes. Like abackeasing, it takesalphabelow0.
When things happen, as fractions of the duration:
arriveis when it first reaches the target.0.3reaches it at 30% of the duration, and the bounces fill the rest. Without it, the first arrival comes sooner the more bounces there are.settleis how long the last bounce takes to settle, from the top of the last bounce to the end.0.2means the last bounce starts to settle at 80% of the duration.tighteningis how much shorter each bounce is than the one before. With0.3, each bounce takes 70% of the time of the previous one, like a ball that bounces faster as it gets lower.0keeps every bounce the same length.
const VideState = require("@VideState")
-- Reaches the target at 20% of the duration, then bounces 4 times, each shorter and lower than the last.
const bouncy = VideState.spring({
height = 0.3,
bounces = 4,
loss = 0.4,
arrive = 0.2,
tightening = 0.3,
})
handler.animate({ tweenDefault = { duration = 0.6, easing = bouncy } })A few things to know:
- The height of each bounce after the first follows from
loss, and you cannot set them one by one. The last bounce is cut a little short by the end of the curve, so the heights are close toloss, not exact. arriveandsettlemust add up to at most0.9, to leave room for the bounces.- A very small
heightwith a highlossmakes the later bounces too small to see. Many bounces on a shortdurationlook frantic. - With a single bounce,
lossandtighteningdo nothing. - The first spring made with a set of options takes a few milliseconds to set up. The result is kept, so making the same spring again costs almost nothing, and each frame costs about as much as
elasticOut.
Parameters
| Name | Type | Description |
|---|---|---|
options | SpringOptions? | Optional. The look of the bounces and when they happen. |
Returns
| Type | Description |
|---|---|
CustomEasing | An easing for the easing setting. |
Errors
| Cause | Message | |
|---|---|---|
| Error | options is not a table | spring options must be a table |
| Error | options has an unknown key | spring options has an unknown key <key> |
| Error | height is not a number above 0 and at most 0.5 | spring height must be a number above 0 and at most 0.5 |
| Error | bounces is not a whole number from 1 to 10 | spring bounces must be a whole number from 1 to 10 |
| Error | loss is not a number above 0 and below 1 | spring loss must be a number above 0 and below 1 |
| Error | arrive or settle is not a number above 0 and at most 0.8 | spring arrive must be a number above 0 and at most 0.8, and the same for settle |
| Error | arrive and settle add up to more than 0.9 | spring arrive and settle must add up to at most 0.9, to leave room for the bounces |
| Error | tightening is not a number from 0 to 0.6 | spring tightening must be a number from 0 to 0.6 |
| Error | anticipation is not a number from 0 to 0.3 | spring anticipation must be a number from 0 to 0.3 |
bounce Added in 0.7.0
VideState.bounce(
options: BounceOptions? -- The height, number, and loss of the bounces
) -> CustomEasingMakes an easing like a ball that drops onto the target and bounces back up toward the start, each bounce lower than the one before, until it rests on the target when the duration ends. The built-in bounceOut is the same idea with a fixed look.
const VideState = require("@VideState")
handler.animate({
tweenDefault = {
duration = 0.6,
-- The first bounce rises 30% of the distance back, there are 4 bounces, and each loses 60% of its height.
easing = VideState.bounce({ height = 0.3, bounces = 4, loss = 0.6 }),
},
})All the settings are optional:
heightis how far the first bounce rises back toward the start, as a fraction of the distance.0.3means a value that moves from 0 to 100 hits 100, goes back to 70, and returns.bouncesis how many times it hits the target and bounces back.lossis how much of its height each bounce loses. With0.5, each bounce is half as high as the one before.
It moves like a falling ball: the drop is the longest part, and a lower bounce is also shorter. It starts at 0 without a jump and never passes the target, so use spring when you want it to go past.
Parameters
| Name | Type | Description |
|---|---|---|
options | BounceOptions? | Optional. The height, number, and loss of the bounces. |
Returns
| Type | Description |
|---|---|
CustomEasing | An easing for the easing setting. |
Errors
| Cause | Message | |
|---|---|---|
| Error | options is not a table | bounce options must be a table |
| Error | options has an unknown key | bounce options has an unknown key <key> |
| Error | height is not a number above 0 and at most 0.9 | bounce height must be a number above 0 and at most 0.9 |
| Error | bounces is not a whole number from 1 to 10 | bounce bounces must be a whole number from 1 to 10 |
| Error | loss is not a number above 0 and below 1 | bounce loss must be a number above 0 and below 1 |
lerp Added in 0.7.0
easing.lerp(
from: T | Source<T>, -- The value at an alpha of 0
to: T | Source<T>, -- The value at an alpha of 1
alpha: number | Source<number> -- How far along it is, usually from 0 to 1
) -> TEvery CustomEasing has a lerp that returns the value between from and to for an alpha, shaped by the curve, without a transition. Use it to ease a value that you drive yourself, such as a slider or a scroll position. from, to, and alpha can be plain values or Vide sources. Read inside a derive or an effect, the result follows them.
const VideState = require("@VideState")
const Vide = require("@packages/Vide")
const bounce = VideState.bounce({ height = 0.3, bounces = 3 })
-- A scroll amount from 0 to 1 that drives the width of a panel with a bounce.
const scroll = Vide.source(0)
const width = Vide.derive(function()
return bounce.lerp(UDim2.fromOffset(100, 40), UDim2.fromOffset(300, 40), scroll())
end)It works with every value that a transition can tween, such as numbers, Color3, UDim2, and tables of numbers. A value that cannot be tweened, such as a string, is from at an alpha that eases to 0, and to otherwise. The alpha is not clamped, so an overshooting curve goes past to.
Parameters
| Name | Type | Description |
|---|---|---|
from | T, or a source of T | The value at an eased alpha of 0. |
to | T, or a source of T | The value at an eased alpha of 1. |
alpha | number, or a source of a number | A finite number. |
Returns
| Type | Description |
|---|---|
T | The value between from and to. It is to when the types of the two differ. |
Errors
| Cause | Message | |
|---|---|---|
| Error | alpha is not a finite number | lerp alpha must be a finite number |
| Error | The curve returns a value that is not a finite number | a custom easing returned a value that is not a finite number |
Reduced motion Added in 0.5.0
Some players turn animations off. setReducedMotion makes every following setState instant, so each onTransition connection receives one frame with the next values and an alpha of 1, and onFinish still runs. Call it from your game's settings, and set it back to false to animate again.
const VideState = require("@VideState")
VideState.setReducedMotion(true)
handler.setState("Hovered") -- plays as one frame, whatever the duration isIt affects every handler, including ones created later, and only the state changes that start after it is called. A transition that is already running keeps playing, and finish ends it at once. A connection cannot opt out, so it also applies to a spinner or a progress bar that you animate with onTransition.
setReducedMotion Added in 0.5.0
VideState.setReducedMotion(
enabled: boolean -- Whether every state change is instant
) -> ()Turns reduced motion on or off. It is off by default.
Parameters
| Name | Type | Description |
|---|---|---|
enabled | boolean | true makes every following setState instant. false animates again. |
Errors
| Cause | Message | |
|---|---|---|
| Error | enabled is not a boolean | setReducedMotion expects a boolean, got <type> |
isReducedMotion Added in 0.5.0
VideState.isReducedMotion() -> booleanReturns whether reduced motion is on.
Returns
| Type | Description |
|---|---|
boolean | true while every state change is instant. Defaults to false. |
Changing settings during a transition
When a setting is a Vide source, it is read every frame. Changing it affects the running transition, and each tween restarts from its current position. The remaining distance is covered with the new settings, so values do not jump, but the easing curve starts again from that point. Plain values are read once and never change.
Types
TransitionOptions Added in 0.1.0 Changed in 0.4.0
type TransitionOptions = {
tweenDefault: TweenSettings?, -- The tween settings of the connection
tweenOverrides: { TweenOverride }?, -- Tween settings for particular state changes
}The options of one onTransition or animate connection.
| Field | Type | Required | Description |
|---|---|---|---|
tweenDefault | TweenSettings | No | The tween settings of the connection. A setting left out takes the built-in default. |
tweenOverrides | { TweenOverride } | No | Tween settings for particular state changes. See Overrides for state changes. |
An unknown key, a non-table value, or a setting at the top level raises an error when the connection is made. A top-level setting such as duration gets the message onTransition options has an unknown key duration. Put duration inside tweenDefault.
TweenSettings Added in 0.4.0 Changed in 0.5.0
type TweenSettings = {
easing: (Easing | Source<Easing>)?, -- The easing curve applied to animatable fields and alpha
duration: (number | Source<number>)?, -- The duration in seconds
speed: Source<number>?, -- How fast the transition advances
delay: (number | Source<number>)?, -- How long a connection waits before its tween starts
}The tween settings of a connection. The easing curves are the standard equations that easings.net lists.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
easing | Easing or Source<Easing> | No | "linear" | The easing curve: a name, or one made with bezier or easing. An unknown name raises an error. |
duration | number or Source<number> | No | 0.25 | The duration in seconds. Must be finite and non-negative. |
speed | Source<number> | No | 1 | A Vide source read every frame. 1 is normal speed, 0 pauses, and larger values play faster. It must never be negative, so a transition never moves backwards. |
delay | number or Source<number> | No | 0 | How long a connection waits, in seconds, before it sends its first frame. Read when a transition starts. Must be finite and non-negative. See Delays. |
Invalid values raise an error when onTransition or animate is called. This includes an unknown key, a non-table value, a negative speed, and a speed that is not a source. A source is also checked on creation, using its current value.
If a source later returns an invalid value, the transition keeps running instead of raising an error (turn on debug.setFallbackWarnings to see a warning): easing falls back to "linear", duration to 0.25, and delay to 0. A negative speed is treated as 0, which pauses the transition, and any other invalid speed is treated as 1. A paused transition keeps its values and does not call listeners again until the speed is above 0.
TweenOverride Added in 0.4.0
type TweenOverride = {
from: { string }?, -- The states the handler leaves
to: { string }?, -- The states the handler enters
tween: TweenSettings, -- The settings for the state changes that match
}One entry of tweenOverrides.
| Field | Type | Required | Description |
|---|---|---|---|
from | { string } | No | The states the handler leaves. Every name must be a state of the handler. Left out means every state. |
to | { string } | No | The states the handler enters. Every name must be a state of the handler. Left out means every state. |
tween | TweenSettings | Yes | The settings for the matching state changes. A setting left out keeps the one of tweenDefault. |
onTransition and animate raise one error that starts with onTransition tweenOverrides has <n> problems: and lists each problem on its own line:
entry <n> must be a tableentry <n> has an unknown key <key>entry <n> from has an unknown state "<state>", and the same fortoentry <n> from is empty, so it matches nothing, and the same fortoentry <n> leaves out both from and to, so it matches every state change. Use tweenDefault for thatentry <n> only matches <state> to <state>, which is not a state changeentry <n> needs a tween tableentry <n>: <message>for an invalid setting, such asonTransition duration must be a finite non-negative numberentries <a> and <b> both match <state> to <state>
Easing Added in 0.5.0
type Easing = TweenName | CustomEasingThe easing of a connection: the name of a built-in curve, or a CustomEasing.
SpringOptions Added in 0.5.0
type SpringOptions = {
height: number?, -- How far the first bounce passes the target
bounces: number?, -- How many bounces
loss: number?, -- How much height each bounce loses
anticipation: number?, -- How far it dips backwards before it moves
arrive: number?, -- When it first reaches the target
settle: number?, -- How long the last bounce takes to settle
tightening: number?, -- How much shorter each bounce is than the last
}The options of spring.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
height | number | No | 0.15 | The first bounce goes this fraction past the target. Above 0 and at most 0.5. 0.15 is 15% past it. |
bounces | number | No | 2 | How many times it passes the target and comes back. A whole number from 1 to 10. |
loss | number | No | 0.5 | The fraction of its height that each bounce loses, above 0 and below 1. 0.5 makes each bounce half as high as the one before. It does nothing with one bounce. |
anticipation | number | No | 0 | How far it dips below the start before it moves, as a fraction of the distance, from 0 to 0.3. 0 is no dip. |
arrive | number | No | When it first reaches the target, as a fraction of the duration, above 0 and at most 0.8. Left out, the bounces are spaced evenly. | |
settle | number | No | How long the last bounce takes to settle, as a fraction of the duration, above 0 and at most 0.8. Left out, the bounces are spaced evenly. | |
tightening | number | No | 0 | How much shorter each bounce is than the one before, from 0 to 0.6. 0.3 makes each bounce take 70% of the time of the previous one. It does nothing with one bounce. |
BounceOptions Added in 0.7.0
type BounceOptions = {
height: number?, -- How far the first bounce rises back toward the start
bounces: number?, -- How many bounces
loss: number?, -- How much height each bounce loses
}The options of bounce.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
height | number | No | 0.25 | The first bounce rises this fraction of the distance back. Above 0 and at most 0.9. |
bounces | number | No | 3 | How many times it hits the target and bounces back. A whole number from 1 to 10. |
loss | number | No | 0.5 | The fraction of its height that each bounce loses, above 0 and below 1. It does nothing with one bounce. |
CustomEasing Added in 0.5.0
type CustomEasing = {
read fn: (number) -> number,
read lerp: <T>(from: T | (() -> T), to: T | (() -> T), alpha: number | (() -> number)) -> T,
}A curve made with VideState.bezier, VideState.easing, VideState.spring, or VideState.bounce. fn takes the progress and returns the eased progress, and lerp returns the value between two values for an alpha. Only these functions make one.
TweenName Added in 0.1.0
type TweenName =
"linear"
| "quadIn" | "quadOut" | "quadInOut"
| "cubicIn" | "cubicOut" | "cubicInOut"
| "sineIn" | "sineOut" | "sineInOut"
| "expoIn" | "expoOut" | "expoInOut"
| "backIn" | "backOut" | "backInOut"
| "elasticIn" | "elasticOut" | "elasticInOut"The valid easing names. Editors suggest them from this type.