Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/litecanvas/plugin-timers
⏰ Plugin to help manage timers in litecanvas games
https://github.com/litecanvas/plugin-timers
litecanvas litecanvas-plugin
Last synced: about 2 months ago
JSON representation
⏰ Plugin to help manage timers in litecanvas games
- Host: GitHub
- URL: https://github.com/litecanvas/plugin-timers
- Owner: litecanvas
- License: mit
- Created: 2024-03-03T22:40:44.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-10-13T16:03:20.000Z (3 months ago)
- Last Synced: 2024-10-13T16:11:32.523Z (3 months ago)
- Topics: litecanvas, litecanvas-plugin
- Language: JavaScript
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Timers plugin for litecanvas
Helpers to manage timers in [litecanvas](https://github.com/litecanvas/engine) games.
## Install
**NPM**: `npm i @litecanvas/plugin-timers`
**CDN**: `https://unpkg.com/@litecanvas/plugin-timers/dist/dist.js`
## Usage
```js
import litecanvas from "litecanvas"
import pluginTimers from "@litecanvas/plugin-timers"litecanvas({
loop: { init },
})use(pluginTimers) // load the plugin
function init() {
wait(5, () => {
// this function will be executed after 5 seconds
})repeat(10, 2, () => {
// this function will be executed 10 times every 2 seconds
})
}
```### Other features
Stop a timer:
```js
const t = wait(5, () => {
// ...
})t.stop() // cancel the timer
```Pause a timer:
```js
const t = wait(5, () => {
// ...
})t.pause() // pause the timer
t.resume() // resume a paused timer
t.running // true if the timer is not paused
```Get/set the remaining time:
```js
const t = wait(5, () => {
// ...
})t.remaining += 10 // add 10 seconds
```Get all active timers:
```js
...
litecanvas()use(pluginTimers, {
exposeTimers: true // enable that settings
})// now you can use the TIMERS variable
TIMERS.forEach((t) => {
// ...
})
```