I've seen those threads here before but none of them really helped me
Here's a code
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(256 * 3, 240 * 3), "My window");
window.setVerticalSyncEnabled(true);
sf::Texture backgroundTexture;
backgroundTexture.loadFromFile("background.png");
sf::Clock mainClock;
sf::View view(sf::FloatRect(0, 0, 256, 240));
sf::Sprite backgroundSprite;
backgroundSprite.setTexture(backgroundTexture);
sf::Vector2f cameraPos(0.0f, 0.0f);
float backWidth = backgroundTexture.getSize().x;
float backHeight = backgroundTexture.getSize().y;
// run the program as long as the window is open
while (window.isOpen())
{
int dt = mainClock.restart().asMilliseconds();
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
float dx = 0.075f * dt;
cameraPos.x += dx;
view.move(dx, 0);
window.setView(view);
// I just render two sprites side by side
int k = cameraPos.x / backWidth;
backgroundSprite.setPosition(backWidth * k, 0);
window.draw(backgroundSprite);
backgroundSprite.setPosition(backWidth * (k + 1), 0);
window.draw(backgroundSprite);
window.display();
}
return 0;
}
Here's the image I'm using: http://i.imgur.com/u0wzBX2.png
What's strange is that my laptop monitor shows very bad results. Scrolling is not smooth at all. My second monitor is showing much better results, but sometimes they're bad too, which is odd. What am I doing wrong? >:(