Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Choppy movement with VSync.  (Read 1407 times)

0 Members and 1 Guest are viewing this topic.

Kain5056

  • Newbie
  • *
  • Posts: 26
    • View Profile
Choppy movement with VSync.
« on: August 30, 2013, 07:38:27 pm »
I have noticed a peculiar problem in my project.
Without VSync, everything seems to work fine.
But when I enable VSync, the movement gets very choppy for some reason.

This is the code I use:

Code: [Select]
void entity::entity_move( sf::Time * delta )
{
    speed = 0.1 * delta->asMicroseconds()/500;

    if( moving_left ) position.x -= speed;
    if( moving_right ) position.x += speed;
}

void entity::entity_show( sf::RenderWindow * window )
{
    entityImage.setPosition( position );
    window->draw( entityImage );
}

int main( int argc , char * argv[] )
{
   
    [...]

    sf::Clock clock;
    sf::Time time;

    while( startup::screen_control.window.isOpen() )
    {
        sf::Event event;
        while( startup::screen_control.window.pollEvent( event ) )
        {
            if( event.type == sf::Event::Closed ) startup::screen_control.window_close();

            [...]

        }

        time = clock.restart();

        sprite_1.entity_move( &time );

        startup::screen_control.window_clear( sf::Color::Cyan );

        sprite_1.entity_show( &startup::screen_control.window );

        startup::screen_control.window_display();
    }

    return 0;
}

What am I doing wrong?  ???