Hi fellow SFML'ers.
I've just starting using SFML 1.6, and I have some trouble getting smooth animation when using vsync. When I print out the time passed since the last frame to the console, I get a list of VERY scattered values like this:
0.016885
0.016948
0.016119
0.0061512
0.0270939
0.0174539
0.0332918
0.0162151
0.017309
0.032944
0.016253
0.0176249
0.0328569
0.00567698
0.0282021
0.0331681
0.016572
0.0166841
0.0172169
0.0327649
0.016468
0.0166309
0.0182922
0.032073
0.016552
0.01722
And the animation looks extremely jerky. By looking at the numbers, it seems like it skips a frame pretty often (when the numbers are in the 0.03'ies, but whats the reason behind a value like 0.0061512..?) And shouldnt these numbers be VERY consistant around 0.01667 (60 FPS)?
In this example, all I do is draw a single moving square to the screen, so it is not the logic updates that are holding things back. When I disable vsync, things look alot smoother, and the values look something like this:
0.000458956
0.000432014
0.000494003
0.000482082
0.000458956
0.000513077
0.000463963
0.000466824
0.000482082
0.000499964
0.000500917
0.000490904
0.000501156
But there is lot of screen tearing, so I dont really like that solution either.
At the very top of my gameloop, I calculate the time passed since the last frame like this:
while (App.IsOpened())
{
float FrameTime = UpdateClock.GetElapsedTime(); //UpdateClock created outside the gameloop
UpdateClock.Reset();
...
and multiply this value into the velocity of my box, to make its logic updates independent of the specific computers' power:
box->Update(FrameTime);
Then I just create a rectangle from the values stored in my box object, and draw it to the screen:
sf::Shape rectangle = sf::Shape::Rectangle(box->GetX(), box->GetY(),
box->GetX() + 100, box->GetY() + 100, sf::Color::Green);
App.Clear();
App.Draw(rectangle);
App.Display();
}
What am I doing wrong?
Has anyone here succeded in making a gameloop with smooth animation running on a Mac?
Sorry if this post seems a little confusing, I've never posted before, and just putting this down on paper turned out to be harder than i thought