I was trying to make an efficient way to drag-and-drop sprites or other objects. I got it to work, but when doing this, I noticed that when my code limited the framerate of the program in order to save processor usage (whether I'm using a fixed timestep or not),
it caused updates that relied on mouse click/move and window interaction to lag.
The following code is a slight modification to one of the site's tutorials (
https://github.com/SFML/SFML/wiki/Tutorial:-Change-Cursor ) that I used as a minimal way to show the problem I'm having:
I have the framerate-limiting code at the beginning commented out, if you uncomment either the FramerateLimit line or the V-sync line (the latter especially, not at same time, I know), it causes lag. Please, what can I do to prevent this?
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Hidden Cursor");
///***Uncommented so that you can see the "lag".***
//window.setMouseCursorVisible(false); // Hide cursor
//***UNCOMMENT ONE OF THESE***
//window.setVerticalSyncEnabled(true);
//window.setFramerateLimit(60);
sf::View fixed = window.getView(); // Create a fixed view
// Load image and create sprite
sf::Texture texture;
texture.loadFromFile("cursor.png");
sf::Sprite sprite(texture);
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
{
window.close();
}
}
// Set position
sprite.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
window.clear();
window.setView(fixed);
window.draw(sprite);
window.display();
}
return EXIT_SUCCESS;
}
I'm sorry but I am just getting so frustrated at this frame stuff, how do all of you not have problems with stuff like this?