HumanBreak/src/plugin/animateController.ts

33 lines
805 B
TypeScript
Raw Normal View History

2022-11-16 23:01:23 +08:00
const animation: ((time: number) => void)[] = [];
let animateTime = 0;
export default function init() {
2022-12-31 21:44:33 +08:00
core.registerAnimationFrame('animateController', true, time => {
2022-11-16 23:01:23 +08:00
if (time - animateTime <= core.values.animateSpeed) return;
for (const fn of animation) {
fn(time);
}
animateTime = core.animateFrame.animateTime;
});
return { addAnimate, removeAnimate };
}
/**
*
* @param fn
*/
export function addAnimate(fn: (time: number) => void) {
animation.push(fn);
}
/**
*
* @param fn
*/
export function removeAnimate(fn: (time: number) => void) {
const index = animation.findIndex(v => v === fn);
2022-11-21 20:00:34 +08:00
if (index === -1) return;
animation.splice(index, 1);
2022-11-16 23:01:23 +08:00
}