I'm having problems.
here is the class that extend Drawable:
class TileMenu : public sf::Drawable{
private:
sf::Sprite monitor;
sf::Text residents;
sf::Text workers;
sf::Text energy;
sf::Text money;
sf::Text pollution;
sf::Text happiness;
sf::Text food;
sf::Text goods;
sf::Font font;
sf::FloatRect close;
public:
TileMenu(Tile& tile, TextureManager& txm);
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
};
and here is the implementation of draw, which i honestly don't know if it is right:
void TileMenu::draw(sf::RenderTarget &target, sf::RenderStates states) const {
target.draw(monitor, states);
target.draw(residents, states);
target.draw(workers, states);
target.draw(energy, states);
target.draw(pollution, states);
target.draw(money, states);
target.draw(happiness, states);
target.draw(goods, states);
target.draw(food, states);
}
in the gameloop class i create a pointer TileMenu* tileMenu and i initialise it as nullptr.
Then i handle the vent of click in a tile and i create in that moment a new TileMenu passing the parameters it needs.
If i call:
renderWindow.draw(*tileMenu);
the program run, but the TileMenu is not shown.
where is the problem?
this is the constructor:
TileMenu::TileMenu(Tile &tile, TextureManager& txm, sf::Font font) {
monitor.setOrigin(tile.getCenter());
monitor.setTexture(txm.getRefTex("Monitor"));
renderTexture.create(80,51);
renderTexture.clear(sf::Color(0,0,0,0));
residents.setString((char)tile.getResidents());
residents.setFont(font);
residents.setCharacterSize(8);
residents.setOrigin(19, 8);
renderTexture.draw(residents);
workers.setString((char)tile.getWorkers());
workers.setFont(font);
workers.setCharacterSize(8);
workers.setOrigin(53, 8);
renderTexture.draw(workers);
energy.setString((char)tile.getEnergy());
energy.setFont(font);
energy.setCharacterSize(8);
energy.setOrigin(19, 19);
renderTexture.draw(energy);
food.setString((char)tile.getFood());
food.setFont(font);
food.setCharacterSize(8);
food.setOrigin(53, 19);
renderTexture.draw(food);
happiness.setString((char)tile.getHappiness());
happiness.setFont(font);
happiness.setCharacterSize(8);
happiness.setOrigin(19, 30);
renderTexture.draw(happiness);
money.setString((char)tile.getMoney());
money.setFont(font);
money.setCharacterSize(8);
money.setOrigin(53, 30);
renderTexture.draw(money);
goods.setString((char)tile.getGoods());
goods.setFont(font);
goods.setCharacterSize(8);
goods.setOrigin(19, 41);
renderTexture.draw(goods);
pollution.setString((char)tile.getPollution());
pollution.setFont(font);
pollution.setCharacterSize(8);
pollution.setOrigin(53, 41);
renderTexture.draw(pollution);
monitor.setTexture(renderTexture.getTexture());
std::cout << "menu created" << std::endl;
}
by the way i modified the class, to see if it was a bug or something, now it doesn't inherit from drawable, it doesn't have a draw method, it just have a getter for monitor which is supposed to have a texture created via the RenderTexture and in the game loop i just draw monitor.