Advertisement
RandomGuy32

Remmys Codeschnipsel

Jul 11th, 2014
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function timestamp() {
  2. if (window.performance && window.performance.now){
  3. return window.performance.now();
  4. } else {
  5. return new Date().getTime();
  6. }
  7. }
  8.  
  9. var fps = 60,
  10. step = 1/fps,
  11. dt = 0,
  12. now,
  13. last = timestamp();
  14.  
  15. function frame() {
  16. now = timestamp();
  17. dt = dt + Math.min(1, (now - last) / 1000);
  18. while(dt > step) {
  19. dt = dt - step;
  20. update(step);
  21. }
  22. render(ctx, dt);
  23. last = now;
  24. requestAnimationFrame(frame, canvas);
  25. }
  26. frame();
  27.  
  28. /* ======================================================== */
  29.  
  30. function timestamp() {
  31. if (window.performance && window.performance.now){
  32. return window.performance.now();
  33. }
  34. else {
  35. return new Date().getTime();
  36. }
  37. }
  38.  
  39. var fps = 60,
  40. step = 1 / fps,
  41. dt = 0,
  42. now,
  43. last = timestamp();
  44.  
  45. function frame() {
  46. now = timestamp();
  47. dt = dt + Math.min(1, (now - last) / 1000);
  48. while (dt > step) {
  49. dt = dt - step;
  50. update();
  51. }
  52. render(ctx);
  53. last = now;
  54. requestAnimationFrame(frame);
  55. }
  56.  
  57. /* ===================================================== */
  58.  
  59. var c=document.getElementById("myCanvas");
  60. var ctx=c.getContext("2d");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement