1
Graphics / Nested drawables to manipulate them toghether, sf hierarchy?
« on: September 26, 2009, 07:30:23 pm »
I downloaded the stable 1.5 like a month ago.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include <vector>
#include <SFML/Graphics.hpp>
typedef std::vector<sf::Drawable*> FrameSet;
typedef FrameSet::const_iterator itFrame;
class Layer : public sf::Drawable, public FrameSet {
public :
Layer( const sf::Vector2f& Position = sf::Vector2f(0, 0),
const sf::Vector2f& Scale = sf::Vector2f(1, 1),
float Rotation = 0.f,
const sf::Color& Col = sf::Color(255, 255, 255, 255));
virtual ~Layer();
virtual void Render(sf::RenderTarget& Target) const;
};
Layer::Layer( const sf::Vector2f& Position,
const sf::Vector2f& Scale,
float Rotation,
const sf::Color& Col) : sf::Drawable(Position,Scale,Rotation,Col) {
};
Layer::~Layer(){
};
void Layer::Render(sf::RenderTarget& Target) const {
for( itFrame i = begin() ;i!=end();i++)
Target.Draw(*(*i));
};
int main(){
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "X");
sf::Image image;
image.LoadFromFile("x.png");
sf::Sprite * sp = new sf::Sprite();
sp->SetImage(image);
Layer layer;
layer.push_back(sp);
layer.SetPosition(10,10); //<-Should move the sprite right?
while (true){
App.Clear();
layer.Render(App);
App.Display();
}
}
iterator = mDrawables.begin();
while( iterator != mDrawables.end() ) {
renderWindow->Draw(
/*This is the messy part, how do I change its position/rotation to mantain the relative distance
but adding its father position (without accumulating) (got it?)*/
/*This obviously doesn't work but it shows the idea.*/
(*mDrawables) + father->GetPosition()
(*mDrawables) + father->GetRotacion()
);
++iteradorDibujables;
}