Hello!
I have a RenderingSystem that loops through a vector of SpriteBatches, one for each texture atlas/spritesheet. The SpriteBatch has a VertexArray that has quads for each instance of X-type entity that uses that texture.
Spritebatch
class SpriteBatch : public sf::Drawable, public sf::Transformable
{
public:
unsigned int m_VerticesCount;
sf::VertexArray m_Vertices;
sf::Texture* m_pTexture;
public:
SpriteBatch(sf::Texture* texture)
m_pTexture(texture), m_VerticesCount(0)
{
m_Vertices.setPrimitiveType(sf::Quads);
}
void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// Apply the transform
states.transform *= getTransform();
// Apply the tileset texture
states.texture = m_pTexture;
// Draw the vertex array
target.draw(m_Vertices, states);
}
};
RenderingSystem render method.
// Loops through all spritebatches and draws them.
void RenderingSystem::render(sf::RenderWindow& window)
{
for (auto spritebatch : m_SpriteBatches) window.draw(*spritebatch);
}
Do you have any tips on how I would go about ordering the individual quads above/below eachother?
I've come up with this idea about moving the quads(where Z != 0) to a new, temporary SpriteBatch, then loop through all new spritebatches and draw them in order, from lowest to highest Z. (Z values would be stored relative to quad positions and also in each new SpriteBatch.) Does that sound plausible? Or would it be too slow and better to just use some list of entities?
I hope your understand my question, otherwise tell me and I will try to clarify as well as I can.
Thanks!