Helpers to manage timers in litecanvas games.
NPM: npm i @litecanvas/plugin-timers
CDN: https://unpkg.com/@litecanvas/plugin-timers/dist/dist.js
importlitecanvasfrom"litecanvas"importpluginTimersfrom"@litecanvas/plugin-timers"litecanvas({loop: { init },})use(pluginTimers)// load the pluginfunctioninit(){wait(5,()=>{// this function will be executed after 5 seconds})loop(2,()=>{// this function will be executed every 2 seconds})repeat(10,2,()=>{// this function will be executed only 10 times every 2 seconds})}Available for any kind of timer
Stop a timer:
constt=wait(5,()=>{// ...})t.stop()// cancel the timerPause a timer:
constt=wait(5,()=>{// ...})t.pause()// pause the timert.resume()// resume a paused timert.running// true if the timer is not pausedGet/set the remaining time:
constt=wait(5,()=>{// ...})t.remaining+=10// add 10 secondsGet all active timers:
...
litecanvas()use(pluginTimers,{exposeTimers: true// enable that settings})// now you can use the TIMERS variableTIMERS.forEach((t)=>{// ...})