Hi!
First of all I want to say thanks for such a wonderful and simple graphicks libruary. I had a trouble whith Text class while coding. Hear two simplyfied code fragments:
this works properly:
#include <SFML/Graphics.hpp>
using namespace sf;
class A
{
public:
void draw_on(RenderTarget & target)
{
Text text;
Font font;
font.loadFromFile("arial.ttf");
text.setCharacterSize(100);
text.setColor(Color::Red);
text.setFont(font);
text.setString("Experiment");
target.draw(text);
}
};
int main()
{
sf::RenderWindow app(sf::VideoMode(800, 600), "SFML window");
A a;
while (app.isOpen())
{
sf::Event event;
while (app.pollEvent(event))
{
if (event.type == sf::Event::Closed)
app.close();
}
app.clear();
a.draw_on(app);
app.display();
}
return 0;
}
and shows red word "Experiment"
this one shows nothing:
#include <SFML/Graphics.hpp>
using namespace sf;
class A
{
Text text;
public:
void draw_on(RenderTarget & target)
{
Font font;
font.loadFromFile("arial.ttf");
text.setCharacterSize(100);
text.setColor(Color::Red);
text.setFont(font);
text.setString("Experiment");
target.draw(text);
}
};
int main()
{
sf::RenderWindow app(sf::VideoMode(800, 600), "SFML window");
A a;
while (app.isOpen())
{
sf::Event event;
while (app.pollEvent(event))
{
if (event.type == sf::Event::Closed)
app.close();
}
app.clear();
a.draw_on(app);
app.display();
}
return 0;
}
the difference is in place of declaration of
Text text
Please, answer if you know why this happens.