I know there are other threads about this but I haven't found it resolved at all.
Ideally, I would like the game not to use 100% of its allotted CPU budget so that's why I would like to limit the FPS to 60. Doing so however cause a ton of stuttering where the object will stall and hang. It's very minor but obvious. How do big companies get away with completely smooth rendering? Have any of you found a way to make it incredibly smooth.
Here is a VERY simple example that stutters on the latest Mac OSX 10.7.4.
Let me know how it runs for you and what system you are on.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window( sf::VideoMode( 800, 600 ), "Test" );
window.setVerticalSyncEnabled( true );
window.setFramerateLimit(60);
sf::Vector2f player1(380, 280);
sf::RectangleShape paddle1(sf::Vector2f(40, 40));
sf::Clock clock;
sf::Time time;
float dt = 0;
const int speed = 100;
// Start the game loop
while (window.isOpen())
{
// Poll for events
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
window.close();
// Escape pressed : exit
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
window.close();
}
// Check for user input
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
player1.y += speed * dt;
// Check for user input
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
player1.y -= speed * dt;
// Restart the clock and get the delta time
time = clock.restart();
dt = time.asSeconds();
// Update the object positions
paddle1.setPosition(player1.x, player1.y);
// Clear screen
window.clear();
// Draw the sprites
window.draw(paddle1);
// Update the window
window.display();
}
return EXIT_SUCCESS;
}
If we can get this fixed, that would be great. Let's pool information if we can.
Edit: Seems that this is fixed on Windows 7 by making it full screen. Going to full screen on OSX makes the screen shift up by 1/4-1/3. Not sure why. I still see the stuttering though.