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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - JesseGuarascia

Pages: [1]
1
System / Re: Handling sf::Clock inconsistent times
« on: May 01, 2014, 01:59:58 am »
It's not a HUGE jump ahead, but I'm extremely picky and sometimes can notice stuff like that. Just bugs me seeing that little jump even though you're definitely not paying attention to that stuff when playing the game. Thanks for clearing up why the timing might happen like that. Much appreciated

2
System / Handling sf::Clock inconsistent times
« on: April 30, 2014, 10:47:08 pm »
So I've been working with SFML for a little while now and wanted to try using delta time to move an object in game. Here's my code:

        AssetManager::LoadTexture("player");
        VideoManager vm;
        Paddle paddle;

        sf::Clock clock;
        sf::Time time = sf::milliseconds(0);
        float lastDelta = 0;

        while (vm.isWindowOpen())
    {
                vm.Update();

                sf::Time curTime = clock.getElapsedTime();
                sf::Time frameDelta = curTime - time;
               
                std::cout << frameDelta.asMilliseconds() << std::endl;

                paddle.Update(frameDelta.asMilliseconds());

                time = curTime;

                vm.Clear();
                paddle.Render(&vm);
                vm.Display();
    }

        AssetManager::UnloadAssets();

    return 0;

The problem is though that I get some strange timings in the system that seems to be messing with the movement of the object and resulting in it sort of skipping ahead a little bit sometimes. I'm getting a pretty constant 16 milliseconds per update with vsync on, but sometimes it becomes 17 (rounding, makes sense I suppose) or in some sort of common instances, it becomes 33 or 1 or 0 and I would be okay with this if it wasn't for the fact that the skipping around of the object is somewhat noticeable. Is there any way to deal with this big time jump? The 33 milliseconds literally skips the object ahead, it's really annoying for me.

Not sure if the object movement code is relevant but here it is:
        sf::Vector2f vel;

        // Use user input to determine direction of paddle
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
                vel.x = PADDLE_SPEED;
        } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)){
                vel.x = -PADDLE_SPEED;
        }

        pos.x += vel.x * (delta / 1000.f);
        pos.y += vel.y * (delta / 1000.f);
 

Pages: [1]
anything