Before when using inheritance, I could draw all my objects using this recursive function:
void Object::innerDraw(sf::RenderTarget& target, sf::RenderStates states)
{
states.transform *= Object::getTransform(); //translate by this object's position
this->Draw(target, states); //draw this object
for (Object *child : m_children)
{
if(child->isVisible)
child->innerDraw(target, states); //draw all children
}
}
However, I am now looking at a component design where the graphics component pushes it's sprite to the renderer Renderer::toDraw.push_back(&sprite);
The renderer then draws all the sprites in it's container
for (sf::Drawable *Entity : toDraw)
{
target.draw(*Entity, state); // (state isn't doing any transforming here)
}
How can I be able to draw things relative to parents position?