Hi all,
So I am getting weird results when moving my character is not smooth.. it actually skips at the middle center of the window.. When I disable both functions it doesn't appear to skip anymore..
I try to do bare bone to see if it was something I did in the code, I found this in the forum and would like to know if you see frame skipped using the example below because in my computer it seems to do..
thanks..
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
window.setVerticalSyncEnabled(true);
sf::Vector2f player1(10, 10);
sf::RectangleShape paddle1(sf::Vector2f(10, 30));
sf::Clock clock;
sf::Time time;
float dt = 0;
const int speed = 500;
// 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;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
player1.x -= speed * dt;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
player1.x += 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;
}
see in youtube