void gui::addMenuButton(int x, int y, string name){
//place text on top of the position of button (the sprite)
sf::Text text(name, sf::Font::getDefaultFont(), 16);
text.setColor(sf::Color(0,0,0));
text.setPosition(x+(35*btns.size()), y);
btns.push_back(buttons());
//add button details
btns[btns.size()-1].text = text;
btns[btns.size()-1].children = 0;
btns[btns.size()-1].x = x;
btns[btns.size()-1].y = y;
//now generate the sprite
sf::Texture texture;
texture.loadFromFile("img/transparent.jpg");
sf::Sprite sprite;
sprite.setTexture(texture);
sprite.setPosition((float) x, (float) y);
sprite.setScale(text.getGlobalBounds().width, text.getGlobalBounds().height);
sprite.setColor(sf::Color(0,0,0));
btns[btns.size()-1].sprite = sprite;
}
As you can see, I wish to create a sprite with a transparent texture with the same height & width as the text object. However, it seems when I call the function
getGlobalBounds() on the text object to get its height & width, it's never accurate.
E.g:
without sprite:
with sprite: