You can get “millis” like so, but be warned that it is limited to the fixed point math range of ± 32,767, or just over 32 seconds.
var millis
export function beforeRender(delta) {
millis += delta
}
Early prototypes/experiments with Pixelblaze had a t
global that was millis()'s. By itself it wasn’t super useful in animations, so patterns would usually scale it to some interval.
For measuring the passage of time for e.g. a debounce timer or to prevent something from triggering too often, you can use a count-up or count-down timer. I wouldn’t recommend using timestamps and calculating deltas that way.
e.g. with exported vars so you can see it go:
export var upcountingTimer = 0
export var upcountingTimerDone = false
export var downcountingTimer = 1000
export var downcountingTimerDone = false
export function beforeRender(delta) {
if (upcountingTimer < 1000) {
upcountingTimer += delta
if (upcountingTimer >= 1000) {
//timer is done!
upcountingTimerDone = true
}
}
if (downcountingTimer > 0) {
downcountingTimer -= delta
if(downcountingTimer <= 0) {
//time is done!
downcountingTimerDone = true
}
}
t1 = time(.1)
}
You can also scale delta
if you don’t want to work in milliseconds.
There’s a seconds based version of setTimeout/clearTimeout API similar to JavaScript: