Timer.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <p class="desc">
  12. This class is an alternative to [page:Clock] with a different API design and behavior.
  13. The goal is to avoid the conceptual flaws that became apparent in [page:Clock] over time.
  14. <ul>
  15. <li>[name] has an [page:.update]() method that updates its internal state. That makes it possible to call [page:.getDelta]() and [page:.getElapsed]() multiple times per simulation step without getting different values.</li>
  16. <li>The class can make use of the Page Visibility API to avoid large time delta values when the app is inactive (e.g. tab switched or browser hidden).</li>
  17. </ul>
  18. </p>
  19. <h2>Code Example</h2>
  20. <code>
  21. const timer = new Timer();
  22. function animate( timestamp ) {
  23. requestAnimationFrame( animate );
  24. // timestamp is optional
  25. timer.update( timestamp );
  26. const delta = timer.getDelta();
  27. // do something with delta
  28. renderer.render( scene, camera );
  29. }
  30. </code>
  31. <h2>Examples</h2>
  32. <p>
  33. [example:webgl_morphtargets_sphere WebGL / morphtargets / sphere]
  34. </p>
  35. <h2>Constructor</h2>
  36. <h3>Timer()</h3>
  37. <h2>Methods</h2>
  38. <h3>[method:this connect]( [param:Document document] )</h3>
  39. <p>
  40. Connects the timer to the given document. Calling this method is not mandatory to use the timer
  41. but enables the usage of the Page Visibility API to avoid large time delta values.
  42. </p>
  43. <h3>[method:this disconnect]()</h3>
  44. <p>
  45. Disconnects the timer from the DOM and also disables the usage of the Page Visibility API.
  46. </p>
  47. <h3>[method:Number getDelta]()</h3>
  48. <p>
  49. Returns the time delta in seconds.
  50. </p>
  51. <h3>[method:Number getElapsed]()</h3>
  52. <p>
  53. Returns the elapsed time in seconds.
  54. </p>
  55. <h3>[method:this setTimescale]( [param:Number timescale] )</h3>
  56. <p>
  57. Sets a time scale that scales the time delta in [page:.update]().
  58. </p>
  59. <h3>[method:this reset]()</h3>
  60. <p>
  61. Resets the time computation for the current simulation step.
  62. </p>
  63. <h3>[method:this dispose]()</h3>
  64. <p>
  65. Can be used to free all internal resources. Usually called when the timer instance isn't required anymore.
  66. </p>
  67. <h3>[method:this update]( [param:Number timestamp] )</h3>
  68. <p>
  69. timestamp -- (optional) The current time in milliseconds. Can be obtained from the
  70. [link:https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame requestAnimationFrame]
  71. callback argument. If not provided, the current time will be determined with
  72. [link:https://developer.mozilla.org/en-US/docs/Web/API/Performance/now performance.now].<br /><br />
  73. Updates the internal state of the timer. This method should be called once per simulation step
  74. and before you perform queries against the timer (e.g. via [page:.getDelta]()).
  75. </p>
  76. <h2>Source</h2>
  77. <p>
  78. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  79. </p>
  80. </body>
  81. </html>
粤ICP备19079148号