Multiple SpriteRender Components


Is it possible to have an entity that has multiple Sprites associated with it?

I’m looking to have a monster displayed on a battlefield with a healthbar.

The entity will have one SpriteRender that represents the monster, and another SpriteRender that represents the current state of its healthbar.

The healthbar sprite will have an offset defined in the spritesheet ron file.

However I cannot have two SpriteRenders on the same entity at once, the last SpriteRender to be added will be the only SpriteRender associated with the entity.

I don’t want to have to create an entirely separate entity just for the healthbar as the monster and its healthbar should be one entity on its own.

Does amethyst offer any solutions to this kind of problem?

P.S The amethyst engine is amazing, I’ve been loving every step of development with it.


1 Like

(Azriel Hoh) #2

Hiya, the underlying ECS library (specs) only supports one instance of a component per entity. The solution I’d recommend is this one:

and attach a Parent component to the healthbar entity, where the value is Parent { entity: monster_entity }. That would help to automatically update the healthbar’s Transform to be where the monster is.



Thanks for the suggestion @azriel91

It would be nice to just be able to stuff another SpriteRender component into the entity or use a vector of SpriteRender components.

For the meantime I will just have to use your solution, although I think having the healthbar as a child component of the monster entity will probably be easiest for updating transformations.

Thanks for your help.