Advertisement
Guest User

Untitled

a guest
May 29th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. /*
  2. *
  3. * Creates a loop for custom animations, paused by default
  4. *
  5. * Use:
  6. * var loop = new Loop();
  7. * loop.update = function(delta, time) {
  8. * // Animate stuff
  9. * };
  10. *
  11. * loop.resume();
  12. * loop.pause();
  13. *
  14. */
  15.  
  16. define([
  17. 'three',
  18. ], function() {
  19.  
  20. return function() {
  21. var _this = this;
  22.  
  23. _this.update = function() {};
  24.  
  25. _this.stop = false;
  26. _this.clock = new THREE.Clock();
  27. var delta = 0;
  28. var time = 0;
  29.  
  30. var loop = function() {
  31. if (_this.stop) return;
  32. requestAnimationFrame(loop);
  33. delta = _this.clock.getDelta();
  34.  
  35. // Avoid jumps upon reactivation
  36. if (delta > 0.4) delta = 0;
  37. time += delta;
  38.  
  39. _this.update(delta, time);
  40. };
  41.  
  42. _this.pause = function() {
  43. _this.stop = true;
  44. };
  45.  
  46. _this.resume = function() {
  47. _this.stop = false;
  48. requestAnimationFrame(loop);
  49. };
  50. };
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement