feat: loop
This commit is contained in:
parent
cf05b0b137
commit
9d876ab2c4
|
@ -8,6 +8,7 @@ export {
|
|||
} from './animation-frame';
|
||||
export {default as AnimationView} from './animation-view';
|
||||
export {default as Lfo} from './lfo';
|
||||
export * from './loop';
|
||||
export {default as Ticker} from './ticker';
|
||||
export {default as TimedIndex} from './timed-index';
|
||||
export {default as Transition, TransitionResult} from './transition';
|
||||
|
|
16
packages/timing/src/loop.js
Normal file
16
packages/timing/src/loop.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
export const createLoop = (ticker, {frequency = 1 / 60, sampler = Date.now} = {}) => {
|
||||
let lastTime = sampler();
|
||||
return setInterval(
|
||||
() => {
|
||||
const now = sampler();
|
||||
const elapsed = (now - lastTime) / 1000;
|
||||
lastTime = now;
|
||||
ticker(elapsed);
|
||||
},
|
||||
1000 * frequency,
|
||||
);
|
||||
};
|
||||
|
||||
export const destroyLoop = (id) => {
|
||||
clearInterval(id);
|
||||
};
|
Loading…
Reference in New Issue
Block a user