BTW, if the line below is commented out, it will be fast enough:
window.setFramerateLimit(60);
-----------------------------------------------------
When navigating on the map, it is not smooth enough, especially when the resolution of the view is high.
Any way to optimize? Thanks.
int main()
{
sf::View view(sf::FloatRect(0, 0, 1280, 720));
sf::Texture texture;
texture.loadFromFile("world.png");
sf::Sprite map(texture);
sf::RenderWindow window(sf::VideoMode(640, 480), "test view");
window.setFramerateLimit(60);
// run the main loop
while (window.isOpen())
{
// handle events
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
default:
break;
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
view.move(0, -4);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
view.move(-4, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
view.move(0, 4);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
view.move(4, 0);
}
window.clear();
window.setView(view);
window.draw(map);
window.display();
}
return 0;
}