Timer
Inherits Observable
Observable which counts down from a max value in realtime whenever played via Timer:Play.
Includes utility methods for mapping this "remaining time" value into more complex animationed sequences.
Constructor
Dex.Timer
Dex.Timer({
duration: number,
isPlaying: CanBeObservable<boolean>?,
playOnChange: Observable<any>?,
}) -> Timer
Creates a new Timer Observable, the value of which decreases in realtime after Timer:Play is called.
Props:
duration is a required prop that specifies the initial time of the timer.
isPlaying specifies that timer should play and stop depending on an
observable boolean value. If set to true, the timer will immediately start
playing.
playOnChange specifies that the timer should restart whenever an input
observable changes.
Timers can safely be garbage collected while dereferenced, unsubscribed, and unused by a VirtualInstance.
INFO
Timers 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.
Usage Example:
local timer = Dex.Timer({
duration = 10,
isPlaying = true,
})
local frame = Dex.New("Frame")({
-- Opaque for 5 seconds, then fades to Transparent over 5 seconds:
BackgroundTransparency = timer:Alpha(5, 0),
})
Types
TimerProps
interface TimerProps {}Type that specifies the props for constructing a Timer observable (via Dex.Timer)
duration is a required prop that specifies the initial time of the timer.
isPlaying specifies that timer should play and stop depending on an
observable boolean value. If set to true, the timer will immediately start
playing.
playOnChange specifies that the timer should restart whenever an input
observable changes.
Functions
Play
Timer:Play() → ()Starts the Timer Observable. The observable will update with new values every heartbeat in real-time until it is stopped.
Stop
Timer:Stop() → ()Stops the Timer Observable, reseting the remaining time.
Pause
Timer:Pause() → ()Pauses the Timer Observable at its current remaining time position.
Pause
Timer:Pause() → ()Sets the current remaining time of the Timer.
SetDuration
Timer:SetDuration(duration: number) → ()Sets the duration of the Timer.
Lerp
Creates an observable that outputs an interpolated value between the start value and end value based on the current remaining time.
Alpha
Timer:Alpha(startTime: number,endTime: number) → AlphaDerives an observble number that maps the remaining time from from 0 at the provided start time, and 1 at the provided end time.