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

Author Topic: sf::Time::asSeconds vs sf::Time::asMilliseconds  (Read 3895 times)

0 Members and 1 Guest are viewing this topic.

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
sf::Time::asSeconds vs sf::Time::asMilliseconds
« 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Time::asSeconds vs sf::Time::asMilliseconds
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: sf::Time::asSeconds vs sf::Time::asMilliseconds
« Reply #2 on: December 30, 2013, 11:14:34 am »
Keep in mind that milliseconds are returned as integers, [...]
Oh, that explains it. Thanks :)