JavaECS-Docs/docs/component/component.md

52 lines
1.2 KiB
Markdown

*| [JavaECS](../../README.md) | [docs](../overview.md) | component*
# Component
### Contents
[About](#About)
## About
Components are raw data that gets associated with an entity.
For an Object-Oriented language like Java, they are objects.
Each component is an array of objects, containing the data that should be associated with the entity.
E.g.: A position component is defined such as:
``` java
class position{
double x = 0.0;
double y = 0.0;
}
```
<br>
As the component is simply an object, the associated data can be anything, including scripts:
``` java
class script{
String statement = "";
Function<void> foo = () -> {
statement += "boo";
};
}
```
<br>
<br>
Two different usages of this data can then be applied:
1. System-less data usage - which stores data but does not have a system that interacts with it every frame
and
2. System-based interaction - which utilises the current data (of one or more components) to check if certain conditions have been met.
I.e.:
The `position` component might not have a `position_system`, but may be utilised by the `collision_system`, which may use `position.x` and `position.y` to determine the location of the entity.
See [System](../system/system.md) for more information.