Animation.js 688 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. class Animation {
  2. constructor( nodes, info ) {
  3. this.nodes = nodes;
  4. this.info = info;
  5. this.animationLoop = null;
  6. this.requestId = null;
  7. this._init();
  8. }
  9. _init() {
  10. const update = ( time, frame ) => {
  11. this.requestId = self.requestAnimationFrame( update );
  12. if ( this.info.autoReset === true ) this.info.reset();
  13. this.nodes.nodeFrame.update();
  14. this.info.frame = this.nodes.nodeFrame.frameId;
  15. if ( this.animationLoop !== null ) this.animationLoop( time, frame );
  16. };
  17. update();
  18. }
  19. dispose() {
  20. self.cancelAnimationFrame( this.requestId );
  21. }
  22. setAnimationLoop( callback ) {
  23. this.animationLoop = callback;
  24. }
  25. }
  26. export default Animation;