https://github.com/uetchy/timecapsule
Timeline based high-precision event invoke system
https://github.com/uetchy/timecapsule
Last synced: about 2 months ago
JSON representation
Timeline based high-precision event invoke system
- Host: GitHub
- URL: https://github.com/uetchy/timecapsule
- Owner: uetchy
- License: mit
- Created: 2018-06-25T07:15:26.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-29T08:39:25.000Z (almost 8 years ago)
- Last Synced: 2025-02-03T02:17:01.446Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TimecapsuleJS
```shell
npm install --save timecapsule
```
## Usage
```js
const { Timecapsule } = require('timecapsule')
const group = new Timecapsule()
group.add(0, () => {
console.log('animation start')
})
group.add(1.2, () => {
console.log('show background')
})
group.add(3.2, () => {
console.log('show stars')
})
```
or
```js
const { Timecapsule, Capsule } = require('timecapsule')
const group = new Timecapsule([
new Capsule(0.0, () => console.log('animation start')),
new Capsule(1.2, () => console.log('show background')),
new Capsule(3.2, () => console.log('show stars')),
])
```
### Sync with time interval
```js
let time = 0
setInterval(() => {
group.invoke(time)
time += 0.1
}, 100)
```
### Sync with music
```js
const { AudioPlayer } = require('timecapsule/util/audioplayer')
const audioSource = {
name: 'bgm',
buffer: arbitoraryArrayBuffer,
oneTimeUpdate: group.invoke,
onEnded: () => console.log('music ended'),
}
const player = new AudioPlayer()
player.addSource(audioSource).then(() => {
player.play('bgm')
})
```