Hi,
Guys i am having trouble implementing game loops in flash.I read this article i found on the net http://gafferongames.com/game-physics/fix-your-timestep/
Here is my code in as3
//Original Code:
float t = 0.0f;
const float dt = 0.01f;
float currentTime = time();
float accumulator = 0.0f;
while (!quit)
{
float newTime = time();
float deltaTime = newTime - currentTime;
currentTime = newTime;
accumulator += deltaTime;
while (accumulator>=dt)
{
integrate(state, t, dt);
t += dt;
accumulator -= dt;
}
render(state);
}
//AS code
private var FPS = 50 / 1000;
private var current_time = getTimer()
mc.addEventListenerEvent.ENTER_FRAME,game)
private function game_loop(e:Event):void
{
if (FPS <= 0) throw new Error("INFINITE LOOP");
var _new_time:int = getTimer();
var _time_difference:Number = (_new_time - current_time);
_time_difference /= 1000;
current_time = _new_time;
excess_buffer_time += _time_difference;
while (excess_buffer_time >= FPS)
{
time_elapsed += FPS;
excess_buffer_time -= FPS;
updateState(time_elapsed,FPS);
}
renderVisualState();
actual_time += FPS
if (actual_time > 1)
{
removeEventListener(Event.ENTER_FRAME, game_loop);
}
}
What i dont undestand is how can i use t and dt to integrate and move objects? i.e say moving a car, acceleration,velocity etc. Can anybody help with regards to this?