SFML community forums

Help => System => Topic started by: didii on December 30, 2013, 12:21:04 am

Title: sf::Time::asSeconds vs sf::Time::asMilliseconds
Post by: didii on December 30, 2013, 12:21:04 am
Hi,

I've noticed that using sf::Time::asMilliseconds is not reliable. When trying to move a sprite, it's speed is depended on the fps which should not be the case. How is this happening?
Changing all sf::Time::asMilliseconds to sf::Time::asSeconds makes all speeds consistent. I used
sf::Sprite::move(speed*sf::Time::asMilliseconds,0);

I've added the file I used for testing this. Use Num1 to swap between unlimited and 30fps (using sf::RenderWindow::setFramerateLimit) and Num2 to swap between the use of sf::Time::asSeconds and sf::Time::asMilliseconds. Note how the object slows down when switching from unlimited framerate and sf::Time::asSeconds to sf::Time::asMilliseconds.

Did I do something wrong or is it really SFML?
Title: Re: sf::Time::asSeconds vs sf::Time::asMilliseconds
Post by: Nexus on December 30, 2013, 01:46:32 am
It's not unreliable, it's simply not precise enough. Keep in mind that milliseconds are returned as integers, thus if a second has more than 1000 frames, a frame will have duration zero.
Title: Re: sf::Time::asSeconds vs sf::Time::asMilliseconds
Post by: didii on December 30, 2013, 11:14:34 am
Keep in mind that milliseconds are returned as integers, [...]
Oh, that explains it. Thanks :)