I changed the keyboard input method and there was no change. So it seems my main loop is being updated with a weird delta time. Any idea how to fix it to be more smooth?
I hope you only relate this to the smoothness and not to the low speed (otherwise you'd have completly ignored the first part of my previous answer...).
You hopefully took it out of the event loop, right?
I've taken your code and implemented a quick test case and it works fine, no choppy movements:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window( sf::VideoMode( 800, 600 ), "Test" );
window.setVerticalSyncEnabled( true );
sf::Vector2f player1(10, 10);
sf::Vector2f player2(590, 10);
sf::RectangleShape paddle1(sf::Vector2f(10, 30));
sf::RectangleShape paddle2(sf::Vector2f(10, 30));
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);
paddle2.setPosition(player2.x, player2.y);
// Clear screen
window.clear();
// Draw the sprites
window.draw(paddle1);
window.draw(paddle2);
// Update the window
window.display();
}
return EXIT_SUCCESS;
}
Also if you think the delta time is too small, then you should either work with a
fixed timestep, or only updated it every second (or half a second).