Skip to main content

Tween

Observable

Inherits Observable

Writeable observable which holds a value which can be re-assigned via State:Set

Constructor


Dex.Tween

Dex.Tween<T>(
    initialValueOrPlayInput: T | Observable<TweenParams<T>>
) -> Tween<T>

Creates a new Tween observable which simulates transitions between values over time.

If an initial value is passed in, the tween will start at the initial value provided must be played by calling the Tween:Play method

If an input observable is passed in, the tween will automatic play based on whenever that observable changes, using [TweenParams] specified by the input observable's current value.

Tweens can either be played by calling the :Play() method

local tween = Dex.Tween(0)
tween:Play({
    goal = 1,
    info = TweenInfo.new(0.1)
})

…or automatically play when an input state holding a params table changes:

local input = Dex.State(0)
local tween = Dex.Tween(Dex.Map(input)(function(currentInput)
    return {
        goal = input,
        info = TweenInfo.new(0.1)
    }
end))
input:Set(1)

Both methods of tween dispatching can be useful in different scenarios.

INFO

Tweens must currently be Subscribed or Mounted to exhibit expected behavior. This is a requirement for all realtime-simulated observables, which enables safe garbage collection when writing Dex components.

Functions

Play

Tween:Play(paramsTweenParams<T>) → ()

Types

interface TweenParams<T> {
goalT,
startT?,
completed(() → ())?,
cancelled(() → ())?,
}

Plays

Show raw api
{
    "functions": [
        {
            "name": "Play",
            "desc": "Plays",
            "params": [
                {
                    "name": "params",
                    "desc": "",
                    "lua_type": "TweenParams<T>"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 181,
                "path": "src/Observables/Tween.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "TweenParams<T>",
            "desc": "",
            "fields": [
                {
                    "name": "info",
                    "lua_type": "TweenInfo,",
                    "desc": ""
                },
                {
                    "name": "goal",
                    "lua_type": "T,",
                    "desc": ""
                },
                {
                    "name": "start",
                    "lua_type": "T?,",
                    "desc": ""
                },
                {
                    "name": "completed",
                    "lua_type": "(() -> ())?,",
                    "desc": ""
                },
                {
                    "name": "cancelled",
                    "lua_type": "(() -> ())?,",
                    "desc": ""
                }
            ],
            "source": {
                "line": 23,
                "path": "src/Observables/Tween.luau"
            }
        }
    ],
    "name": "Tween",
    "desc": "#### Inherits [Observable]\n\nWriteable observable which holds a value which can be re-assigned via\n[State:Set]\n\n## Constructor\n\n---\n\n### Dex.Tween\n\n```ts\nDex.Tween<T>(\n    initialValueOrPlayInput: T | Observable<TweenParams<T>>\n) -> Tween<T>\n```\n\nCreates a new [Tween] observable which simulates transitions between values\nover time.\n\nIf an initial value is passed in, the tween will start at the initial value\nprovided must be played by calling the [Tween:Play] method\n\nIf an input observable is passed in, the tween will automatic play based on\nwhenever that observable changes, using [TweenParams] specified by the input\nobservable's current value.\n\nTweens can either be played by calling the `:Play()` method\n```lua\nlocal tween = Dex.Tween(0)\ntween:Play({\n    goal = 1,\n    info = TweenInfo.new(0.1)\n})\n```\n\n…or automatically play when an input state holding a params table changes:\n```lua\nlocal input = Dex.State(0)\nlocal tween = Dex.Tween(Dex.Map(input)(function(currentInput)\n    return {\n        goal = input,\n        info = TweenInfo.new(0.1)\n    }\nend))\ninput:Set(1)\n```\n\nBoth methods of tween dispatching can be useful in different scenarios.\n\n:::info\nTweens must currently be ***Subscribed*** or ***Mounted*** to exhibit\nexpected behavior. This is a requirement for all realtime-simulated\nobservables, which enables safe garbage collection when writing Dex\ncomponents.\n:::",
    "tags": [
        "Observable"
    ],
    "source": {
        "line": 85,
        "path": "src/Observables/Tween.luau"
    }
}