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

Author Topic: Issues with drawing an sf::Text vector  (Read 3559 times)

0 Members and 1 Guest are viewing this topic.

hatstrosity

  • Newbie
  • *
  • Posts: 1
    • View Profile
Issues with drawing an sf::Text vector
« on: August 26, 2015, 11:40:42 pm »
Hello, so we've encountered some problems when we try to draw a vector that contains sf::Text objects in it. We have a class that makes the objects, a for loop that puts them into the vector, and a while loop that should theoretically draw them - but that doesn't happen. The compiler also doesn't fling any kind of error at us, so we are not entirely sure what the issue is. Entire source code here -
(click to show/hide)

We're trying to make a roguelike and figured that we would start with making a few basic walls and an @ symbol to move around as the player. We are using sf::Text objects for all of this business, but if there is a more preferable method of doing this, we would love to hear it. Thank you for any help that you can offer on this issue!

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Issues with drawing an sf::Text vector
« Reply #1 on: August 26, 2015, 11:53:28 pm »
You're copying the font in the constructor for texts, rather than referencing it. So, once the constructor is over, the new font you created is destroyed, so the textClass member no longer refers to a valid font. Not an SFML concept. C++ concept. :)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Issues with drawing an sf::Text vector
« Reply #2 on: August 27, 2015, 12:38:00 am »
Dabbertorres already said why it's not working so I'll not address that.

However, I just wanted to say three things:
  • I don't understand why people use "using namespace std". Why not just prefix everything in std namespace with "std::"? You're happy to do it for sf:: so why not std:: ?  ???
  • if there is a more preferable method of doing this, we would love to hear it.
    I would prefer starting with simple geometry than with text characters. sf::RectangleShape is the usual choice since most graphics end up being rectangles anyway so this is a good way to block.
  • Welcome to the forum!  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Issues with drawing an sf::Text vector
« Reply #3 on: August 27, 2015, 08:32:10 am »
  • I don't understand why people use "using namespace std". Why not just prefix everything in std namespace with "std::"? You're happy to do it for sf:: so why not std:: ?  ???
I think it's because people perceive it to be easier, to write that once and then not have to write std:: over and over again. What's more, I have actually seen people using using namespace sf as well as std. As far as I can tell, people ignore all those you say don't use it, because it hasn't gone wrong for them yet, and there are some people you say you should use it. To clarify, I don't support the use of using namespace std, but I'm pretty sure that's why people use it.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Issues with drawing an sf::Text vector
« Reply #4 on: August 27, 2015, 01:10:13 pm »
I think it's because people perceive it to be easier, to write that once and then not have to write std:: over and over again. What's more, I have actually seen people using using namespace sf as well as std.
That's my point. Using using namespace sf as well as std makes more sense from a laziness point of view but one not the other just screams "I saw someone using using namespace std once and now I have to do it." I can understand people who use it to be lazy but if you're going to be lazy, be completely lazy!
p.s. Don't be lazy.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*