SFML community forums

Help => General => Topic started by: idmantob on November 17, 2020, 07:24:32 am

Title: Problems with Text
Post by: idmantob on November 17, 2020, 07:24:32 am
I'm very new to programming. I am trying to set a Text variable in a class
class myclass
{
private:
           Text m_name;
public:
           void setName(Text name);
           Text getName();
}
void setName(Text name)
{
m_name = name
}
Text getName()
{
return m_name;
}

in a .h file:

Text name;
Font font;
fond.loadFromFile(fonts/arial.ttf);
name.setFont(font);
name.setcharacterSize(12);
name.setFillColor(Color::White);
name.setPosition(x,y);
std::stringstream tname;
tname << x;
name.setString(tname.str());
myclass.setName(name);


Then basically I'm doing:
int main()
{
window.draw(name); //this comes back with an exception error
}

I think there's a problem with the font, but not sure. Any suggestions?
Title: Re: Problems with Text
Post by: Stauricus on November 17, 2020, 11:34:36 am
if this is all your code, you forgot to create the RenderWindow inside main:
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
Title: Re: Problems with Text
Post by: Hapax on November 17, 2020, 01:14:15 pm
You would have to be more clear about what is in your ".h" file.

Is that font global, for example? Or is it local and destroyed after assigning it to the text, maybe?