There are countless questions here about whether entities should draw themselves or not. The answer is almost universally no, there should be a renderer. And I do see a point in having a single place where everything is rendered. Makes asset management easier and the code less convoluted.
However, I'm struggling to find a good approach to implement this in my 2D game. Currently, every entity is told to draw itself, and I pass the renderer object to it. Now, I want the renderer to draw each entity, but I don't want the renderer to actually know about entities, so I need a more generic class, e.g. RenderObject
, and a way to construct render objects from entities.
One obvious approach would be to have a GetRenderObject()
method on each entity. However, some of my entities actually draw multiple textures, relative to their position, so I'd probably need a GetRenderObjects()
function instead.
But that wouldn't really remove any rendering logic from my entities. I'd still have to refer particular assets and their positions relative to the entity position in the render objects I create.
So my question is: Doesn't having a renderer mean that my entities don't have any drawing logic anymore? If so, who will generate these render objects? Does it even make sense to take the render objects detour?
And, bonus question: How can this work together with a UI system? I'd rather not have the renderer know about widgets and containers and such, so my hunch so far is to have widgets stick to drawing themselves.