12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- class Animation {
- constructor() {
- this.nodes = null;
- this.animationLoop = null;
- this.requestId = null;
- this.isAnimating = false;
- this.context = self;
- }
- start() {
- if ( this.isAnimating === true || this.animationLoop === null || this.nodes === null ) return;
- this.isAnimating = true;
- const update = ( time, frame ) => {
- this.requestId = self.requestAnimationFrame( update );
- this.nodes.nodeFrame.update();
- this.animationLoop( time, frame );
- };
- this.requestId = self.requestAnimationFrame( update );
- }
- stop() {
- self.cancelAnimationFrame( this.requestId );
- this.isAnimating = false;
- }
- setAnimationLoop( callback ) {
- this.animationLoop = callback;
- }
- setNodes( nodes ) {
- this.nodes = nodes;
- }
- }
- export default Animation;
|