Voilà un code source d'une classe qui peut contenir d'autres objets sf::Drawable. Les objet ajoutés au conteneur sont dessiné totalement par rapport à l'objet mère. Un objet Drawable peut même être rajouté à plusieurs objets Layer. Voilà le code:

Layer.h
#ifndef LAYER_H
#define LAYER_H
 
#include <vector>
#include <SFML/Graphics.hpp>
 
typedef std::vector<sf::Drawable*> FrameSet;
typedef FrameSet::const_iterator itFrame;
 
/*
*	Petite classe simple qui gère le système de couche de drawable.
*	Elle a la même utilisation que std::vector, l'élément à l'indice 0 est le premier affiché.
*/
class Layer :
	public sf::Drawable, public FrameSet
{
 public :
	//!Même constructeur que sf::Drawable
	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();
protected :
	virtual void Render(sf::RenderTarget& Target) const;
};
 
#endif
Layer.cpp
#include "Layer.h"
#include <iostream>
 
Layer::Layer(const sf::Vector2f& Position, const sf::Vector2f& Scale, float Rotation, const sf::Color& Col) : Drawable(Position,Scale,Rotation,Col)
{
}
 
Layer::~Layer()
{
}
 
void Layer::Render(sf::RenderTarget& Target) const
{
	// Let the derived class render the object geometry
	for( itFrame i = begin() ;i!=end();i++)
		Target.Draw(*(*i));
}
 
fr/sources/layer.txt · Last modified: 2009/01/21 21:21 by isra17
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki