Skip to content

Components

Open Javadoc

A component stores the data of an entity and can be modified by systems. Components classes usually only have public properties, because most properties need to be read and set by systems.

Creating components

Components are created by extending the Component class.

Example

public class SpriteRenderer extends Component {
public Texture texture;
}

Adding components to entities

Components can be attached to entities. This will trigger any initialisation system that requires a component of the component’s class.

SpriteRenderer spriteRenderer = entity.addComponent(new SpriteRenderer());

Getting components of entities

Components of entities can be retrieved by referencing the component’s class. However, usage of this method in performance-critical contexts is discouraged, since it is quite slow. Instead, it is recommended to create a system that requires this component.

SpriteRenderer spriteRenderer = entity.getComponent(SpriteRenderer.class);

Toggling components

Components can be activated and deactivated, which will make all systems temporarily ignore them.

component.setActive(false);
component.isActive; // false
component.setActive(true);
component.isActive; // true