Animation.js 629 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. this.nodes.nodeFrame.update();
  13. this.info.frame = this.nodes.nodeFrame.frameId;
  14. if ( this.animationLoop !== null ) this.animationLoop( time, frame );
  15. };
  16. update();
  17. }
  18. dispose() {
  19. self.cancelAnimationFrame( this.requestId );
  20. }
  21. setAnimationLoop( callback ) {
  22. this.animationLoop = callback;
  23. }
  24. }
  25. export default Animation;