1
\$\begingroup\$

I've just started using an entity-component system for the first time and I'm having trouble making some decisions.

Currently I've got a SpriteComponent that holds a sprite, a ContentManagerComponents that holds an instance of a content manager so systems can load the content they need, and a SpriteSystem that requires both components and only has a method to set the sprite, possibly loading it beforehand (sprite rendering and animating is taken care of by other systems).

This kinda looks good, but my main concern is... how is a system that's not SpriteSystem supposed to set the sprite?

Here are my options, as I see them:

  • Have systems that need to change the sprite comunicate with SpriteSystem somehow. Probably a bad idea since it introduces a dependency between systems (?).
  • Move the method to set the sprite to SpriteComponent. Problem is, the method needs a content manager to load the sprite if needed.
  • Get rid of ContentManagerComponent and give SpriteComponent a content manager. But the content manager doesn't only load sprites.

Any help is appreciated.

\$\endgroup\$
3
\$\begingroup\$

Lazy loading!

Add a method to SpriteComponent to let it store the name of the new sprite to load, then let the SpriteSystem load the actual data whenever it comes into play.

To smooth out the loading laggies, preload.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.