View Single Post
  #3 (permalink)  
Old June 5th, 2013, 02:16 PM
ragnarok ragnarok is offline
Registered User
Points: 20, Level: 1
Points: 20, Level: 1 Points: 20, Level: 1 Points: 20, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Posts: 2
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Thanks. That explains (and helps) a lot.

I actually got it to work with the following (only Q&D on the Chrome-Detection, but I think it'll work for the rest of the book):

Code:
Q.gameLoop = function(callback) {    
    if(window['webkitRequestAnimationFrame']) { 
      //Chrome-Detection
      Q.lastGameLoopFrame = 0;
    } else {
      //Firefox-Detection
      Q.lastGameLoopFrame = new Date().getTime();
    }
    
    Q.gameLoopCallbackWrapper = function(now) {
      Q.loop = requestAnimationFrame(Q.gameLoopCallbackWrapper);
      var dt = now - Q.lastGameLoopFrame;
      
      if(dt > 100) { dt = 100; }
      callback.apply(Q,[dt / 1000]);  
      Q.lastGameLoopFrame = now;
    };

    requestAnimationFrame(Q.gameLoopCallbackWrapper);
  };
The Following User Says Thank You to ragnarok For This Useful Post:
sauerkraut (June 5th, 2013)