Bonjour, je lis sur le wiki
https://github.com/SFML/SFML/wiki/TutorialDrawableGroup une suggestion fort intéressante de classe Group, et sa raison principale de ne pas figurer dans la SFML :
The SFML doesn't implement a Group class for ownership reasons: should the Group destroy its elements when it is destroyed?
L'utilisation de std::shared_ptr (c++11) dans cette page wiki, ou du moins sa suggestion, pourrait être fort utile pour régler cette question...
#include <SFML/Graphics.hpp>
#include <memory>
class Group : public sf::Drawable, public std::vector<std::shared_ptr<sf::Drawable>> {
public:
Group();
~Group();
void render(sf::RenderTarget&) const;
};
#include "group.hpp"
Group::Group() :
sf::Drawable(),
std::vector<std::shared_ptr<sf::Drawable>>() {
}
Group::~Group() {
//nada rien, ça marche tout seul.
}
//This is what ables you to do Group.Draw() to draw all the Drawable inside of a Group, and to apply common settings such as position, color, ... to its elements.
void Group::render(sf::RenderTarget& Tar) const {
for(std::vector<std::shared_ptr<sf::Drawable>>::iterator i = begin(); i != end(); ++i) {
Tar.draw(*i);
}
}