0 Members and 1 Guest are viewing this topic.
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;}
Unless you're using a 1x1 pixel texture, which seems unlikely, you need to adjust the scaling factors.
sprite.setScale((text.getGlobalBounds().width/9), (text.getGlobalBounds().height/9));