Reputation: 13
I want to combine let's say sf:RectangleShape and sf::Text into one drawable object so that I only have to call the function mWindow.draw() once for the two objects. Is it possible?
Upvotes: 1
Views: 846
Reputation: 103713
What you can do is implement a class which inherits from sf::Drawable
, and override the draw
function to draw both your rectangle and your text. Your render window will take care of the rest.
class BoxAndText : public sf::Drawable
{
public:
sf::RectangleShape rect;
sf::Text text;
private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const override
{
target.draw(rect, states);
target.draw(text, states);
}
};
Upvotes: 1