EDIT: TO ANYONE READING THIS, IT IS NOT THE BIG JUMP THAT IS THE ISSUE. THAT'S JUST THE GIF LOOPING. THE PROBLEM IS THE JITTERING OF THE IMAGE, BACK AND FORTH IF YOU LOOK CLOSELY.
Hey, everyone. So this is something that I believe
might be a bug, however, I have only been using SFML for about a week now, so I could definitely be doing something wrong.
First of all, let's get my hardware and software specifications out of the way:
RAM: 16GB DDR3
CPU: i5-3570k
GPU: GTX 1060 6GB, most recent drivers 390.77
Monitor #1: 2560 x 1440 @ 144fps w/ G-Sync
Monitor #2: 1280 x 1024 @ 60fps
OS: Windows 10, v. 1709, build 16299
IDE: Visual Studio 2015
SFML Version: 2.4.2
So, here is the problem I'm having. When I try to modify the position of anything related to a sprite, the image of the sprite appears to "jump" back and forth, and I've provided an image of how it looks for me below.
Here is the code that reproduces this problem for me:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(900, 600), "SFML", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);
//window.setVerticalSyncEnabled(true);
//window.setFramerateLimit(144);
//window.setFramerateLimit(60);
int refresh_rate = 60;
float frame_time = (float) 1 / (float) 60;
// Background //
sf::Texture background;
if (!background.loadFromFile("stars.png"))
exit(1);
background.setRepeated(true);
sf::Sprite stars(background);
int posx = 0;
// ---------- //
sf::Clock clock;
sf::Time passed_time;
while ( window.isOpen() ) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::Resized:
window.setView(sf::View(sf::FloatRect(0.f, 0.f, event.size.width, event.size.height)));
break;
}
}
passed_time += clock.restart();
while (passed_time.asSeconds() >= frame_time) {
stars.setTextureRect(sf::IntRect(posx, 0, window.getSize().x, window.getSize().y));
posx += 2;
window.clear();
window.draw(stars);
window.display();
passed_time -= sf::seconds(frame_time);
}
}
}
I've read the entire FAQ and documentation provided for SFML over the last week from
https://www.sfml-dev.org/learn.phpI thought that I might be doing something wrong, and here are outside resources I've utilized so far to try and understand, and come up with, this code above, other than my 3 years of C++ experience in university:
https://gafferongames.com/post/fix_your_timestep/https://maksimdan.gitbooks.io/sfml-and-gamedevelopement/content/frame_rate.htmlhttps://gamedev.stackexchange.com/questions/97675/sfml-game-loop-and-fps-problemsNone of these seemed to fix the skipping problem, and after some more Googling, I found that some people had an issue with Nvidia's "Threaded Optimization" setting, however this had no measurable effect on performance for me when switched from "auto" to "off."
I had also seen that some people had an issue similar to mine depending on what their framerate was set to. So, I tried every possible combination of enabling vertical sync, limiting the frame rate, changing my threading optimization, and changing from debug to release.
None of these were able to remedy the issue. If it is something obvious, please let me know. I've been re-reading the documentation and tutorials for hours (from 7pm - 11pm just today) and would really appreciate any step in the right direction.
Thank you.