I am using delta timing to account for potential drop in frame rate. Only trouble being when I do this, I can notice an ever so slight wobble. I checked out the following JSFiddle coming from a tutorial on the subject and I can even see the wobble there, specifically on the 30fps example. http://jsfiddle.net/straker/bLBjn/
my code is:
var delta = {
now: 0,
last: 0,
difference:0,
time: 1000/60
}
var d = function(val){
return val/delta.time * delta.difference;
}
Then further down at the game loop
delta.last = Date.now();
animate();
function animate(){
delta.now = Date.now();
delta.difference = delta.now - delta.last;
delta.last = delta.now;
//update a sprite
platform.x -= d(10);
requestAnimationFrame( animate );
}
How can I keep the animation smooth?
Date.now
, becauserequestAnimationFrame
calls back with a high-res timestamp as the first argument. There's a handy example on MDN demonstrating that. I don't know if that's the cause of the "wobble" you're seeing though. Try it. – Anko Oct 13 '14 at 15:39