UNPKG

1.65 kBJavaScriptView Raw
1/**
2 * @category Core
3 */
4export class FrameManager {
5 constructor(container) {
6 this.container = container;
7 }
8 /**
9 * Handles the rAF method preparing the next animation frame to be drawn
10 * limiting it if it's needed by the current configuration
11 * @param timestamp
12 */
13 nextFrame(timestamp) {
14 var _a;
15 try {
16 const container = this.container;
17 // FPS limit logic - if we are too fast, just draw without updating
18 if (container.lastFrameTime !== undefined &&
19 timestamp < container.lastFrameTime + 1000 / container.fpsLimit) {
20 container.draw(false);
21 return;
22 }
23 (_a = container.lastFrameTime) !== null && _a !== void 0 ? _a : (container.lastFrameTime = timestamp);
24 const deltaValue = timestamp - container.lastFrameTime;
25 const delta = {
26 value: deltaValue,
27 factor: (60 * deltaValue) / 1000,
28 };
29 container.lifeTime += delta.value;
30 container.lastFrameTime = timestamp;
31 if (deltaValue > 1000) {
32 container.draw(false);
33 return;
34 }
35 container.particles.draw(delta);
36 if (container.duration > 0 && container.lifeTime > container.duration) {
37 container.destroy();
38 return;
39 }
40 if (container.getAnimationStatus()) {
41 container.draw(false);
42 }
43 }
44 catch (e) {
45 console.error("tsParticles error in animation loop", e);
46 }
47 }
48}