I am currently working on a game in Java that uses an entity component system. The game currently has two separate update()
and render()
methods in the game loop however this does not seem to fit with my entity component system. From what I understand, each system in an ECS has an update method but what about say, a rendering system that draws sprites to the screen? How does rendering work with an ECS? One idea could be to have systems that draw on the screen implement a RenderSystem
interface so that they are only used in the rendering method but I've never seen anything like this. Is there a certain way of doing this?
\$\begingroup\$
\$\endgroup\$
1
-
1\$\begingroup\$ Related question: Should actors in a game be responsible for drawing themselves? \$\endgroup\$– PhilippCommented Mar 27, 2017 at 14:25
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
2
A common way to implement rendering in an ECS is to have a Renderer
component on any entity which is supposed to be visible in the game world. This component would hold all the information which is required by the graphic engine (which you can call RenderingSystem
if you like) to visualize this entity.
-
\$\begingroup\$ So a system where the render system holds information about entities to be used every render call? Currently the update() method is called 60 times per second and the render() method is called every loop. So could it be possible to store render information in the render system in the update() function to be later used in the render() function in the renderer? \$\endgroup\$– user93747Commented Mar 27, 2017 at 16:59
-
\$\begingroup\$ @Gigas Certainly. One thing you could handle in Renderer.update is animation. \$\endgroup\$– PhilippCommented Mar 27, 2017 at 19:05