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

Author Topic: Problems with Text  (Read 1326 times)

0 Members and 1 Guest are viewing this topic.

idmantob

  • Newbie
  • *
  • Posts: 1
    • View Profile
Problems with Text
« 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?
« Last Edit: November 17, 2020, 07:49:48 am by idmantob »

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Problems with Text
« Reply #1 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");
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Problems with Text
« Reply #2 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?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*