Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.

How to manage a Component with multiple implementations? #56

Open
patrikturi opened this issue Oct 9, 2015 · 3 comments
Open

How to manage a Component with multiple implementations? #56

patrikturi opened this issue Oct 9, 2015 · 3 comments

Comments

@patrikturi
Copy link

Hello,
I'd like to create a Renderable component with three implementations, Sprite, AnimatedSprite and Shape. How should I do this with anax?
Ideas:

  • I've tried inheriting components from an abstract class component, but my Entity System for the abstract class didn't work (did not contain any entity, however I've added an entity of the child component type).
  • Create all 3 components, and in the filter of the Entity System specify Sprite OR AnimatedSprite OR Shape component. But I did not find a way to do this, I saw only require and exclude filters :/
@miguelmartin75
Copy link
Owner

You should just create three different components:

  • Sprite: used to store information about a sprite (to draw one)
  • Shape: used to store information a shape (to draw one)
  • Animation: stores animation information to animation an entity

Then you should essentially make:

  • an AnimationSystem to animate entities with an animation component
  • a SpriteRenderSystem to render entities with a Sprite component
  • a ShapeRenderSystem to render entities with a Shape component

You can see an animation example in the examples directory.

@patrikturi
Copy link
Author

My problem with your approach is that I need to sort all entities with those components by Z index and draw them in that order. If I have 3 different Systems for rendering I can't do that. This is why I'd like to have only one System for all 3 components. Do you see any other solution for this?

@misopeth
Copy link

You could create a GraphicComponent like this:

class GraphicComponent : public anax::Component
{
public:
    ...
private:
    std::unique_ptr<Sprite>    m_sprite;
    std::unique_ptr<Shape>     m_shape;
    std::unique_ptr<Animation> m_animation;
};

Then a GraphicSystem:

class GraphicSystem : public anax::System<anax::Requires<GraphicComponent>>
{
    ...
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants