Litecanvas plugin to handle simple timers.
litecanvas()
function init() {
// load the plugin
use(pluginSimpleTimer)
// example: alert every 2 seconds
every(2, () => {
alert('hello')
})
// example: alert just once after 5 seconds
// note: return "false" to cancel a timer
// note: "executed" stores the number of times the callback has been called
every(5, (executed) => {
if (executed > 0) return false
alert('once')
})
// note: every(0, fn) runs every frame
let frames = 0
every(0, () => {
frames += 1
})
}
For more advance timers use the Timers plugin.