Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Bundling multiple drawable objects into a returnable object  (Read 1677 times)

0 Members and 1 Guest are viewing this topic.

Aiden_Cohen

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Bundling multiple drawable objects into a returnable object
« on: March 31, 2018, 09:46:59 pm »
I am interested in creating a separate function to draw my menu screen in a game I'm making, how would I accomplish this in sfml and what would i need the function to return?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Bundling multiple drawable objects into a returnable object
« Reply #1 on: April 01, 2018, 06:57:23 pm »
You could create a new class that inherits from sf::Drawable and then override the draw function so that it draws all the objects you need. Then, when you draw your new object, it draws everything at once.

Here's a basic example snippet:
class NewDrawable public sf::Drawable
{
public:
    // ...

private:
    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
    sf::RectangleShape m_rectangle;
    sf::CircleShape m_circle;
    sf::Sprite m_sprite;
}

void NewDrawable::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
        target.draw(m_rectangle);
        target.draw(m_circle);
        target.draw(m_sprite);
}
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything