utils_AnimationTimer.js.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: utils/AnimationTimer.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: utils/AnimationTimer.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/**
  20. * Animation timer should be used to run the update and render loops of the application.
  21. *
  22. * Underneat it uses the requestAnimationFrame() method that calls the function with the same rate as the screen refresh rate.
  23. *
  24. * @class
  25. * @param {Function} callback Timer callback function.
  26. */
  27. function AnimationTimer(callback)
  28. {
  29. /**
  30. * Task of the timer, executed at the timer defined rate.
  31. *
  32. * @type {Function}
  33. */
  34. this.callback = callback;
  35. /**
  36. * Indicates if the timer is currently running, it is set to true on start and reset to false on stop.
  37. *
  38. * @type {boolean}
  39. */
  40. this.running = false;
  41. /**
  42. * ID of the currently waiting timeout clock. Used to cancel the already request execution of the next clock tick.
  43. *
  44. * @type {number}
  45. */
  46. this.id = -1;
  47. }
  48. /**
  49. * Start timer, is the timer is already running does not do anything.
  50. */
  51. AnimationTimer.prototype.start = function()
  52. {
  53. if(this.running)
  54. {
  55. return;
  56. }
  57. this.running = true;
  58. var self = this;
  59. function loop()
  60. {
  61. self.callback();
  62. if(self.running)
  63. {
  64. self.id = requestAnimationFrame(loop);
  65. }
  66. }
  67. loop();
  68. };
  69. /**
  70. * Stop animation timer, should be called when the render loop is no longer in use to prevent code/memory leaks.
  71. *
  72. * If the timer is not stopped the loop will keep running using processing power and consuming memory.
  73. */
  74. AnimationTimer.prototype.stop = function()
  75. {
  76. this.running = false;
  77. cancelAnimationFrame(this.id);
  78. };
  79. export {AnimationTimer};
  80. </code></pre>
  81. </article>
  82. </section>
  83. </div>
  84. <nav>
  85. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnimationTimer.html">AnimationTimer</a></li><li><a href="BarGraph.html">BarGraph</a></li><li><a href="BezierCurve.html">BezierCurve</a></li><li><a href="Box.html">Box</a></li><li><a href="Box2.html">Box2</a></li><li><a href="BoxMask.html">BoxMask</a></li><li><a href="Circle.html">Circle</a></li><li><a href="ColorStyle.html">ColorStyle</a></li><li><a href="DOM.html">DOM</a></li><li><a href="EventManager.html">EventManager</a></li><li><a href="FileUtils.html">FileUtils</a></li><li><a href="Gauge.html">Gauge</a></li><li><a href="GradientColorStop.html">GradientColorStop</a></li><li><a href="GradientStyle.html">GradientStyle</a></li><li><a href="Graph.html">Graph</a></li><li><a href="Helpers.html">Helpers</a></li><li><a href="Image.html">Image</a></li><li><a href="Key.html">Key</a></li><li><a href="Line.html">Line</a></li><li><a href="LinearGradientStyle.html">LinearGradientStyle</a></li><li><a href="Mask.html">Mask</a></li><li><a href="Matrix.html">Matrix</a></li><li><a href="MultiLineText.html">MultiLineText</a></li><li><a href="Node.html">Node</a></li><li><a href="NodeConnector.html">NodeConnector</a></li><li><a href="NodeGraph.html">NodeGraph</a></li><li><a href="NodeSocket.html">NodeSocket</a></li><li><a href="Object2D.html">Object2D</a></li><li><a href="Path.html">Path</a></li><li><a href="Pattern.html">Pattern</a></li><li><a href="PatternStyle.html">PatternStyle</a></li><li><a href="PieChart.html">PieChart</a></li><li><a href="Pointer.html">Pointer</a></li><li><a href="QuadraticCurve.html">QuadraticCurve</a></li><li><a href="RadialGradientStyle.html">RadialGradientStyle</a></li><li><a href="Renderer.html">Renderer</a></li><li><a href="RoundedBox.html">RoundedBox</a></li><li><a href="ScatterGraph.html">ScatterGraph</a></li><li><a href="Style.html">Style</a></li><li><a href="Text.html">Text</a></li><li><a href="UUID.html">UUID</a></li><li><a href="Vector2.html">Vector2</a></li><li><a href="Viewport.html">Viewport</a></li><li><a href="ViewportControls.html">ViewportControls</a></li></ul><h3>Global</h3><ul><li><a href="global.html#writeFile">writeFile</a></li></ul>
  86. </nav>
  87. <br class="clear">
  88. <footer>
  89. Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sat Sep 17 2022 14:24:36 GMT+0100 (Hora de verão da Europa Ocidental)
  90. </footer>
  91. <script> prettyPrint(); </script>
  92. <script src="scripts/linenumber.js"> </script>
  93. </body>
  94. </html>