Animation.js 713 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. this.requestId = null;
  22. }
  23. setAnimationLoop( callback ) {
  24. this.animationLoop = callback;
  25. }
  26. }
  27. export default Animation;