Entities#

Entities represent individual objects within a scene. An entity is simply a collection of components with a unique ID.

An entity's capabilities are therefore defined by the components it contains rather than by a class hierarchy.

As examples, a player entity can have this structure:

Player[ ID, Components[ $transform, $sprite, $health, $playerMarker ] ]

while an enemy entity can resemble this:

Enemy[ ID, Components[ $transform, $sprite, $health, $enemyMarker ] ]

As seen above, neither entity (nor their components) contains movement, rendering, combat or other game logic. They contain only the data required by systems.

Lastly, entities with the same component structure can still have completely different runtime values.

Creating an Entity#

Create an entity using the createEntity function as shown below:.

import { createEntity } from "gamekit-engine/core/entity";
import { $transform, $sprite } from "gamekit-engine/core/prefabs";

export const player = createEntity("player", [
  $transform(),
  $sprite({ src: "player.png", size: [64, 64], layer: 0 }),
  health(100),
]);

Compatibility With Systems#

For an entity to be compatible with a system and be processed by it, it needs to contain all the components required by the system.

As an example, the built-in $spriteRenderer is a system which renders sprite images. An entity is compatible with the system if it has at least the $transform and $sprite components.

Next Steps#

In the next guide, we'll explore systems in more detail.