SFML community forums
Help => System => Topic started by: Chainsaw_Rabbit on January 23, 2012, 02:27:58 am
-
I have a few problems with sf:Clock, these two lines should usually work or did i something wrong?
sf::Clock clock;
float current_time = clock.GetElapsedTime() ;
I dont get it to work, instead I always get:
error C2440: '=' : cannot convert from 'sf::Time' to 'int'
-
That's strange. In my mind it should say
cannot convert from 'sf::Time' to 'float'
Anyway, you are getting the error because GetElapsedTime() returns a sf::Tme object. I believe you can get the time as a float that represents seconds by using clock.GetElapsedTime().AsSeconds();
I haven't played with SFML2 yet, though, so I may be wrong.
Take a look at the documentation here: http://www.sfml-dev.org/documentation/2.0/classsf_1_1Time.php
-
That's strange. In my mind it should say Quote:
cannot convert from 'sf::Time' to 'float'
:oops:
Oh, I was testing around with integers (obviously it wasnt the solution) and posted the wrong error code, sorry.
clock.GetElapsedTime().AsSeconds();
Works! Thanks, you just made my day! :D
-
You must be using SFML 2.0. You must declare an object of type Time and set it equal to <clockname>.getElapsedTime() then you can use <timename>.asSeconds() or asMilliseconds() or a lot of other stuff to get the time.
-
You must be using SFML 2.0. You must declare an object of type Time and set it equal to <clockname>.getElapsedTime() then you can use <timename>.asSeconds() or asMilliseconds() or a lot of other stuff to get the time.
And yet another use less post!
You see his question was answered with the post from model76 on the 23th of January, there would've been no need to dig this up again.
The content of your text is also not really usefull because in C++ <something> is reserved for templates and thus <timename> gets very confusing.
Since this post is already brought up from the 'dead' and maybe someday someone will find it with the search function here it is a bit better:
SFML 2.0 introduces a new class called sf::Time, it solves the problem of having only one resolution for time.
sf::Clock::getElapsedTime() doesn't return a fixed value in float anymore, it returns as sf::Time class. If you want you can not store this returned class or just go ahead and access it.
There are three diffrent functions, see the documentation (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Time.php)for more details.