I was doing some testing yesterday on a project I'm working on, and I realized that drawing the sf::RectangleShape (which I had a lot of) wasn't performing as fast as using a sf::Sprite. However, I also wanted a setSize functionality and I was planning to do something which would have benefited from a setVertexColor function.
So, this isn't exactly a project, but I wrote a SimpleSprite class which fullfills those needs.
It should also duplicate all functionality of a sf::Sprite, so you should (in theory) be able to replace any sf::Sprite objects with SimpleSprite and would not be required to do any other code changes. I've seen a couple of posts where people were talking about stuff like this, so I decided to post this.
Here's the public functionality of SimpleSprite:
SimpleSprite ( );
explicit SimpleSprite ( const sf::Texture &texture );
SimpleSprite ( const sf::Texture &texture, const sf::IntRect& rect );
void setSize ( const sf::Vector2f &size);
void setSize ( float size_x, float size_y );
void setTexture ( const sf::Texture &texture, bool updateTextureRect = false );
void setTextureRect ( const sf::IntRect &rect );
void setColor ( sf::Color color );
void setVertexColor ( unsigned int index, sf::Color color );
// getters
const sf::Vector2f& getSize () const;
const sf::Texture* getTexture () const;
const sf::IntRect& getTextureRect () const;
// Warning: This function may not return correct results if you have used setVertexColor(..)
// This function is the equivalent of calling getVertexColor(0)
const sf::Color& getColor () const;
const sf::Color& getVertexColor ( unsigned int index ) const;
The .hpp and .cpp are attached.
Edit: Updated - the default behavior of setTexture so that updateTextureRect is false by default.
[attachment deleted by admin]