This article walks you through the steps of creating a custom entity with child entities using the Ellipse2D class. Everything you see here can also be done with the Editor by just dragging components and entity templates into your entity. The Smiley entity can be reused and be combined with any other component as well (rotate, scale, outline, physics, etc.)

The Ellipse2D class combines the following components (the same will be added if you drag in an Ellipse in the Editor):

Ellipse2DComponent for the ellipse x and y radius

Polygon2DComponent for the polygon points

As well as Vector2D for the position, Size (automatically calculated from the points) and Color

Many other components can be attached via the properties available in the Entity2D base class (Rotation, Scale, Outline, Pivot, etc.) or just by attaching more components like Image, GradientColor, Rotate, Velocity, Gravity, etc.

Let's build a new entity based on just that entity. Let's start with a unit test like in the other Tutorials:

For the mouth a simple ellipse is not going to cut it, but we can use a trick and just render 2 ellipses with the second smaller one overwriting the first one with yellow again, leaving just the mouth part in black. We should also render the eyes next. Keep in mind that doing this kind of fine-tuning is much easier with the Editor and should not be done in code, we just want to illustrate how things work here.

and we are done. Now we are free to use that entity as many times as we want. Lets put it in a method and use it as a template for many more smileys rotating and scaling around on the screen. Keep in mind we do not want to change the Smiley template entity parameters programmatically, just define it once and then change whatever you want in the derived entities based on the template.

Also notice we added a Rotate component and TapGesture trigger with a ChangeColorAction (to Orange) when clicking on a smiley. Each entity created from the template will get all these features as well and any future improvements also.