Home c++ blinks square in SDL2 C++

blinks square in SDL2 C++

Author

Date

Category

When driving and motionlessness, the square periodically disappears for a moment. This happens when using the Graphics.updateWindow () class method. Please tell me how to get rid of the problem.

Graphics.cpp


Void Graphics :: DrawRect (SDL_Rect * RECT, UINT8_T RGBA [4])
{
  SDL_setRenderDRAWColor (Renderer, RGBA [0], RGBA [1], RGBA [2], RGBA [3]);
  SDL_RenderFillRect (Renderer, RECT);
  SDL_RENDERDRAWRECT (Renderer, RECT);
  SDL_RENDERPRESENT (Renderer);
}
Void Graphics :: UPDATEWINDOW (UINT16_T FPS)
{
  SDL_DELAY (1000 / FPS); // 1000 Miliseconds. Result Is Miliseconds Delay
  SDL_SetRenderDRAWColor (Renderer, 0, 0, 0, 0);
  SDL_RENDERFILLRECT (Renderer, & amp; Background);
}

Answer 1

The problem was solved. Thank you, @ こきん .
Moved the SDL_RenderPresent call from the DrawRect method to the beginning of the UpdateWindow method
Now the Graphics.updateWindow ()

method

void graphics :: updatewindow (uint16_t fps)
{
  SDL_RENDERPRESENT (Renderer);
  SDL_DELAY (1000 / FPS); // 1000 Miliseconds. Result Is Miliseconds Delay
  SDL_SetRenderDRAWColor (Renderer, 0, 0, 0, 0);
  SDL_RENDERFILLRECT (Renderer, & amp; Background);
}

Thanks again.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions