Skip to content

⏰ Plugin to help manage timers in litecanvas games

License

Notifications You must be signed in to change notification settings

litecanvas/plugin-timers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Timers plugin for litecanvas

Helpers to manage timers in litecanvas games.

Install

NPM: npm i @litecanvas/plugin-timers

CDN: https://unpkg.com/@litecanvas/plugin-timers/dist/dist.js

Usage

import litecanvas from "litecanvas"
import pluginTimers from "@litecanvas/plugin-timers"

litecanvas({
  loop: { init },
})

use(pluginTimers) // load the plugin

function init() {
  wait(5, () => {
    // this function is called after 5 seconds
  })

  every(0.1, () => {
    // this function is called every 0.1 seconds (100 ms)
  })

  repeat(10, 2, () => {
    // this function is called every 2 seconds (100 ms)
    // but just 10 times
  })
}

Other features

Cancel a timer:

const t = wait(5, () => {
  // ...
})

t.cancel() // cancel the timer

Pause a timer:

const t = wait(5, () => {
  // ...
})

t.pause() // pause the timer

t.resume() // resume a paused timer

t.paused // true if the timer is paused

Get all active timers:

const all = timers()

all.forEach((t) => {
  // ...
})

About

⏰ Plugin to help manage timers in litecanvas games

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published