# Fixed time step - game loop

**URL:** <https://forum.kirupa.com/t/fixed-time-step-game-loop/312943>\
**Category:** programming\
**Created:** [August 16, 2010, 3:42pm UTC](https://forum.kirupa.com/t/fixed-time-step-game-loop/312943 "2010-08-16T15:42:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![basilisk](https://avatars.discourse-cdn.com/v4/letter/b/f05b48/32.png) [@basilisk](https://forum.kirupa.com/u/basilisk)\
**Post date:** [August 16, 2010, 3:42pm UTC](https://forum.kirupa.com/t/fixed-time-step-game-loop/312943/1 "2010-08-16T15:42:06Z")

</div>

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/](http://gafferongames.com/game-physics/fix-your-timestep/)  
Here is my code in as3

```auto

//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?
