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