   Choppy Sprite Movement
  I am having problems with moving my sprites smoothly. After reading this article I updated my game loop to the last one described (I also put the code below): http://dewitters.koonsolo.com/gameloop.htmlThe sprits are moving at a constant speed regardless of frame rate, but fast moving sprites still look choppy. I have it so on every update_game() a car moves 10.0f. When the display_game() function is called I do the following:car.x_view_pos = car.x_pos + (speed * interpolation)Does anyone have any ideas on how to smooth this out? It is frustrating because the game is running at 100+ fps.Game Loop    const int TICKS_PER_SECOND = 25;    const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;    const int MAX_FRAMESKIP = 5;    DWORD next_game_tick = GetTickCount();    int loops;    float interpolation;    bool game_is_running = true;    while( game_is_running ) {   loops = 0;   while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) {  update_game();  next_game_tick += SKIP_TICKS;  loops++;   }   interpolation = float( GetTickCount() + SKIP_TICKS - next_game_tick )    / float( SKIP_TICKS );   display_game( interpolation );    }
Quote:I have it so on every update_game() a car moves 10.0fIs speed == 10.f?Try slowing the game down by setting the fps to 2 seconds every frame, and examining the results.  I generally handle interpolation by view = (current - previous) * interp + previous, ensuring that current is only set once during a group of update()s.   ;  Yes the speed is equal to 10.0f.Do you mean setting the TICKS_PER_SECOND to 2, so it only updates twice a second? I gave this a try and it definitely seems smoother, but still not quite right. I am not sure I understand your formula, what exactly are previous and current? Can you explain it a bit further? I am wondering if it is because around the time it does the game updates, it doesn't display as many frames to screen, so it appears to skip forward a little bit. I tired setting it so the game_display is limited to 60 frames per second; this smooth it out a bit, but it still seems to flicker when the car moves at high speeds because it is jumping to far between frame displays.Thanks for the help.   ;  If speed changes anywhere from the last rendered frame and before it is integrated with car.x_view_pos, then you might notice a discontinuity.  For example:pos = 0, speed = 10, and view(interp) = pos + speed * interp.In between the first two logic updates, view will correctly interpolate from 0 to 10.  On the beginning of the next logic update, the observed position is 10.  During the logic update, however, speed is changed to 2, and is then integrated with the position and results in 2.  Here is where you might notice a jump; the position was last observed to be at 10, but is now at 2, interloping to 4. Now think of it this way:speed = 10, pos = 0, previous_pos = 0, and view(interp) = previous_pos + (pos - previous_pos) * interp.When the position is set, previous_pos is assigned the position's old value.  In between logic updates, the observed position will be interpolated between previous_pos and pos.Quote:I am not sure I understand your formula, what exactly are previous and current? Can you explain it a bit further?observed = (current - previous) * interp + previouscurrent and previous are states of the variable, say if foobar were to be 4, and you were to assingn 7 to it, then current would be 7, and previous would be 4:observed = (7 - 4) * interp + 4observed = 3 * interp + 43 * 0 + 4 = 43 * .5 + 4 = 5.53 * 1 + 4 = 7;  Thanks for clearing that up. Unfortunately I am still getting some choppiness. I added some logging to try an narrow down what is actually happening. I can see it is properly calculating the view between updates, but there seems to be a different number of displays between updates. Sometimes it is able to display 4 times between updates and sometimes it is only able to display 2 times between updates. I think this is the reason it is looking choppy. If it displays the car four times between pos=10 and pos=20, a only twice between pos=20 and pos=30, then it will look choppy. Is there anyway around this?   ;  try thisinterpolation = 0.0;display_game( interpolation );the reason being is if the fps > 100this should look ok, (interpolation is only really needed at lower fps)if it does look ok then I assume youre calculing the interpolation wrongly   ;  zedz, when I set the interpolation to 0 it looks okay at speed=10, but when speed hits 20, it looks too flickery because it is jumping to far on each game update. I think my interpolation calculations are correct, but as I stated above it doesn't always display the same number of frames between game updates.   ;  Does anyone know of a decent way to try and display the same number frames between game updates? I could limit the display frames to 60 fps, but I don't want to do this because if someone has a machine that can display more than that I would want to do that (as it would make the game look even smoother).   ;Quote:Original post by BrokenKingpinzedz, when I set the interpolation to 0 it looks okay at speed=10, but when speed hits 20, it looks too flickery because it is jumping to far on each game update. That makes it sound like your problem isn't with interpolation at all, but a lack of double buffering.   ;  Maybe flicker was the wrong word. I just meant that it doesn’t look that great when it is jumping that far at one time. I do not think the double buffer is the issue. This is how I am initializing:int Init_Direct3D(HWND hwnd, int width, int height, int fullscreen){    //initialize Direct3D    d3d = Direct3DCreate9(D3D_SDK_VERSION);    if (d3d == NULL)    {   MessageBox(hwnd, "Error initializing Direct3D", "Error", MB_OK);   return 0;    }    //set Direct3D presentation parameters    D3DPRESENT_PARAMETERS d3dpp;ZeroMemory(&d3dpp, sizeof(d3dpp));    d3dpp.Windowed = (!fullscreen);    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    d3dpp.BackBufferCount = 1;    d3dpp.BackBufferWidth = width;    d3dpp.BackBufferHeight = height;    d3dpp.hDeviceWindow = hwnd;    //create Direct3D device    d3d->CreateDevice(   D3DADAPTER_DEFAULT,    D3DDEVTYPE_HAL,    hwnd,   D3DCREATE_SOFTWARE_VERTEXPROCESSING,   &d3dpp,    &d3ddev);    if (d3ddev == NULL)    {   MessageBox(hwnd, "Error creating Direct3D device", "Error", MB_OK);   return 0;    }    //clear the backbuffer to black    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);    //create pointer to the back buffer    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);    return 1;}This is what I have in my display function://start renderingif (d3ddev->BeginScene()){d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );//draw tiles onto the scroll buffermap.DrawTiles();//draw the scroll window onto the back buffermap.DrawScrollWindow();// draw spritesmainChar.DisplaySprite(&map, interpolation);//stop renderingd3ddev->EndScene();}    //display the back buffer on the screen    d3ddev->Present(NULL, NULL, NULL, NULL);