J
J
joger2011-10-19 14:53:45
Canvas
joger, 2011-10-19 14:53:45

Canvas: uniform movement

There is a large moving image. There is an impression that the movement is jerky.
Can it be cured?

Example: jurassic-lab.com/test2/

Thanks

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
ertaquo, 2011-10-19
@ertaquo

Try something like this:

var lastTime = (new Date()).getTime();
var process = function(){
  var currTime = (new Date()).getTime();
  var deltaTime = currTime - lastTime;
  lastTime = currTime;

  deltaTime /= 1000.0; // получаем в секундах, с дробной частью. просто для удобства

  var speed = 1000; // 1000 пикселей в секунду

  x += speed * deltaTime;
  y += speed * deltaTime;

  setTimeout(process, 10);
};

A
Alexey, 2011-10-19
@alexxxst

In Chrome and IE9 there are no problems, but in FF - yes, jumps ... :)

J
joger, 2011-10-19
@joger

additional question: flash in this case will do better?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question