The fact is that when driving the cursor in the sfml window when you press the movement key, the character moves faster and jerks. Accordingly, as the coordinates of the cursor do not change, or in general the cursor is outside the window, everything goes smoothly. At the same time, in the neighboring project, practically everything is the same and it works perfectly, the only difference in the code is the dynamic creation of the window and access to it through the pointer.
void System::CreateWindow(int Width, int Height, string Title) { window.create(VideoMode(Width,Height), Title); window.setVerticalSyncEnabled(true); window.setFramerateLimit(iFrameLimit); } void System::MainLoop(StateBase& state) { while(window.isOpen()) { Clock(); HandleEvents(event); Update(fTime); Render(window); } } void System::HandleEvents(Event event) { while (window.pollEvent(event)) { if (event.type == event.Closed) window.close(); states.back()->HandleEvents(this); } } void System::Clock() { fTime = clock.getElapsedTime().asMicroseconds(); clock.restart(); fTime /= fGameSpeed; if (fTime > fGameTick ) fTime = fGameTick; } Neighboring project:
void CGameEngine::mainLoop() { while (window->isOpen()) { //TimeWorks float time = (float)clock.getElapsedTime().asMicroseconds(); clock.restart(); time = time / 800; //Event processor sf::Event event; while (window->pollEvent(event)) { if (event.type == sf::Event::Closed) window->close(); } CGameEngine::CGameEngine() { gameName = "HellFinger"; playerTileMap = "sprite.png"; mapTileMap = "map.png"; loadConfig(7); window = new sf::RenderWindow(sf::VideoMode(screenResolution.x, screenResolution.y), gameName); camera = new CameraView(0, 0, screenResolution.x, screenResolution.y); player = new Entity(playerTileMap, PLOTM.left, PLOTM.top, PLOTM.width, PLOTM.height); mapImage.loadFromFile("Resources/Images/" + mapTileMap); mapTexture.loadFromImage(mapImage); mapSprite.setTexture(mapTexture); } PS The second code is not mine.