add Artplayer.USE_RAF

This commit is contained in:
Harvey Zack committed 2023-08-26 00:03:26 +08:00
1 parent 6fc1532ada
commit 9ba838aa52
10 files changed
+105 -11

No files matched your search

@@ -0,0 +1,19 @@
export default function updateInit(art) {
if (art.constructor.USE_RAF) {
let timer = null;
(function update() {
if (art.playing) {
art.emit('raf');
}
if (!art.isDestroy) {
timer = requestAnimationFrame(update);
}
})();
art.on('destroy', () => {
cancelAnimationFrame(timer);
});
}
}