Assum we use physic engine like box2d or p2.js. And both graphic and physic updating are aprox 60 fps.
What is better?
1. Update gfx position right after physic body moved?
GameObject.prototype.integrate = function() {
this.body.integrate(); //body has changed his position according to physic simulation
this.gfx.x = this.body.x;
this.gfx.y = this.body.y;
}
2. or in separeted loop?
requestAnimFrame(() => {
world.eachObject((obj) => {
obj.gfx.x = obj.body.x;
obj.gfx.y = obj.body.y;
});
});