If you are unfamiliar with Entity Component System (ECS), we recommend reading Introduction to ECS before proceeding.
- A
Position
component may contain thex
,y
, andz
coordinates of an entity. - A
Health
component may contain thecurrent
andmax
health of an entity.
Defining Components
By convention, components are defined in thecomponent
directory in its own separate files.
You can easily create a new component and register it to the world by following these steps:
1
Define the component struct
A component is defined as a Go struct. It must implement the
Name()
method which returns a unique name of the component. This is used to identify the component in the world./component/component_health.go
2
Register the component in main.go
Components must be registered in the world before they can be used. This is done by calling the
RegisterComponent
function.main.go