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

Author Topic: sf::clock doesn't work  (Read 8234 times)

0 Members and 1 Guest are viewing this topic.

Chainsaw_Rabbit

  • Newbie
  • *
  • Posts: 2
    • View Profile
sf::clock doesn't work
« 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?

Code: [Select]
sf::Clock clock;
float current_time = clock.GetElapsedTime() ;


I dont get it to work, instead I always get:


Quote
error C2440: '=' : cannot convert from 'sf::Time' to 'int'

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
sf::clock doesn't work
« Reply #1 on: January 23, 2012, 03:39:08 am »
That's strange. In my mind it should say
Quote
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
Code: [Select]
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

Chainsaw_Rabbit

  • Newbie
  • *
  • Posts: 2
    • View Profile
sf::clock doesn't work
« Reply #2 on: January 23, 2012, 08:45:40 am »
Quote
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.

Code: [Select]

clock.GetElapsedTime().AsSeconds();


Works! Thanks, you just made my day! :D

Bocaj

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: sf::clock doesn't work
« Reply #3 on: April 04, 2012, 10:23:56 pm »
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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: sf::clock doesn't work
« Reply #4 on: April 04, 2012, 10:46:31 pm »
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 for more details.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything