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;
}
Please read this (http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368).
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.
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.