SFML community forums
Help => General => Topic started by: dark ninjuh on October 09, 2014, 08:10:22 am
-
I got the book, did the first chapter. and i wanted to add frames like it did. i added text no problem , its the getting the frames to show on the text i cant manage to figure out. Should i just NOT do it the way the book does? i dont know how to convert a float to string . compiler throws "conversion is ambiguous" at me.
sf::String frames;
frames = TimePerFrame.asSeconds(); // <-- this throws error I thought that's how you used this, apparently not
Scary = sf::Text(frames,scaryFont);
sadly have been trying to solve this one problem for over an hour. no solutions found.
(most people that i see posting on here helped WRITE the book, figured no more needed to be added to the post than my little bit)
-
That's not code from the book. The book code is also on GitHub and reads like this (https://github.com/SFML/SFML-Game-Development-Book/blob/master/01_Intro/Source/Game.cpp#L101).
-
Look up std::to_string (http://en.cppreference.com/w/cpp/string/basic_string/to_string).
(Or std::stringstream)
-
That's not code from the book. The book code is also on GitHub and reads like this (https://github.com/SFML/SFML-Game-Development-Book/blob/master/01_Intro/Source/Game.cpp#L101).
i was referring to the way TimePerFrame is declared in the book. and i cant load GitHub pages.
-
.asSeconds() returns a number (a float, in this case).
To assign it to a string, you'll need to use some transformation method. Jesper mentioned the two main ones.
If you see it being used as a string in the book, it's likely it was being used in a stringstream. If you want to assign it/convert it directly to a string, you'll need the std::to_string().