Hello,
I'm having trouble with the sf::Text class. Here is part of my code:
// gui.cpp
playerCardGUI::playerCardGUI()
{
texture.loadFromFile("data\\GUI\\playercard.png");
texture.setSmooth(false);
sprite.setTexture(texture);
}
playerCardGUI::~playerCardGUI()
{
}
void playerCardGUI::create(unsigned short int argOwner, NATIONALITY natl, sf::Vector2f pos)
{
texture.loadFromFile("data\\GUI\\playercard.png");
texture.setSmooth(false);
sprite.setTexture(texture);
playerName.setFont(data.mainFont);
health.setFont(data.mainFont);
ammoMag.setFont(data.mainFont);
ammoTotal.setFont(data.mainFont);
playerName.setString("Name");
owner = argOwner;
if(natl == US)
txNational.loadFromFile("data\\GUI\\ally_US.png");
else if(natl == GR)
txNational.loadFromFile("data\\GUI\\axis_GR.png");
sprite.setPosition(pos);
playerName.setPosition(pos);
}
void playerCardGUI::update(int HP, int ammo, int totalAmmo)
{
std::stringstream stream;
stream << HP;
health.setString(stream.str());
stream.clear();
stream << ammo;
ammoMag.setString(stream.str());
stream.clear();
stream << totalAmmo;
ammoTotal.setString(stream.str());
}
void playerCardGUI::draw()
{
}
// gui.h
#ifndef GUI_H
#define GUI_H
class playerCardGUI
{
private:
// graphics variables
sf::Sprite sprite;
sf::Texture texture;
sf::Sprite spClass, spNational;
sf::Texture txClass, txNational;
// text variables
sf::Text playerName;
sf::Text health;
sf::Text ammoMag, ammoTotal;
// misc variables
unsigned short int owner;
public:
playerCardGUI();
~playerCardGUI();
void create(unsigned short int argOwner, NATIONALITY natl, sf::Vector2f pos);
void update(int HP, int ammo, int totalAmmo);
void draw();
friend class Player;
};
#endif // GUI_H
Specifically, the issue is with playerName. When I try to compile this, it works fine-- until I close the main program window. Then the process continues to run until I manually end it using the Windows Task Manager.
I don't see anything wrong with my code. Does anyone else see anything wrong?
Thanks in advance.