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

Author Topic: sfml book  (Read 1356 times)

0 Members and 1 Guest are viewing this topic.

dark ninjuh

  • Newbie
  • *
  • Posts: 13
    • View Profile
sfml book
« 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.

Code: [Select]
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)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: sfml book
« Reply #1 on: October 09, 2014, 08:17:01 am »
That's not code from the book. The book code is also on GitHub and reads like this.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: sfml book
« Reply #2 on: October 09, 2014, 08:18:35 am »
Look up std::to_string.
(Or std::stringstream)

dark ninjuh

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: sfml book
« Reply #3 on: October 09, 2014, 08:19:50 am »
That's not code from the book. The book code is also on GitHub and reads like this.
i was referring to the way TimePerFrame is declared in the book. and i cant load GitHub pages.

Hapax

  • Hero Member
  • *****
  • Posts: 3360
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sfml book
« Reply #4 on: October 09, 2014, 08:58:16 pm »
.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().
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything