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

Author Topic: Trying to display text returns me an error  (Read 1705 times)

0 Members and 1 Guest are viewing this topic.

Canvas

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Trying to display text returns me an error
« on: June 21, 2014, 09:19:11 pm »
Hey guys, I'm trying to display some text in my game but I keep getting the error displayed in the image I have attached coming up, the font is not null, nor the character size, nor the test or colour, what am I doing wrong here?

Here is the render code

//Objects and text
    for (int i = 0; i < DisplayObjects.size(); i++)
    {
        auto object = DisplayObjects.at(i);
        Window.draw(object->GetSprite());
        if (object->IsTextObject())
        {
            Window.draw(object->GetText());
        }
    }

Also here is the code I have which sets up the text
void DisplayObject::SetText(std::string setText)
{
        displayText.setFont(font);
        displayText.setColor(sf::Color(0, 0, 0));
        displayText.setCharacterSize(24);
        displayText.setString(text);
        text = setText;
        textObject = true;
}

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Trying to display text returns me an error
« Reply #1 on: June 21, 2014, 10:07:08 pm »
Please read this.

And are you sure you want to copy the other object?
auto object = DisplayObjects.at(i);

Same applies for the string parameter. Also, at() is a really awful function to use during iteration. You should work with iterators, indices are for random access.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Canvas

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Trying to display text returns me an error
« Reply #2 on: June 21, 2014, 11:49:15 pm »
How would i build an iterator over my vector? also the copying of the object was there just for debugging

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Trying to display text returns me an error
« Reply #3 on: June 22, 2014, 12:07:11 am »
for (const auto& object : DisplayObjects) {
}
Would be the simple option.

Or if you want iterators
for (auto it = begin(DisplayObjects); it != end(DisplayObjects); ++it) {
}
 

And there are more options.
« Last Edit: June 22, 2014, 12:12:46 am by Jesper Juhl »

 

anything