Core Concepts#

GameKit is designed around the Entity-Component-System (ECS) architecture. ECS separates game data from the logic that operates on it, providing a data-oriented alternative to the traditional object-oriented GameObject model.

Components#

Components describe individual pieces of an entity's state. They are plain JavaScript objects and don't contain any behavior or logic.

As an example, the $transform component simply stores a position array (x,y), rotation, and scale array (sx,sy).

Entities#

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

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.

Systems#

Systems implement game logic/behavior.

During runtime, GameKit provides systems with compatible entities for it to process and a system can read and write data of an entity's components.

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

In the example above, the $spriteRenderer does not need to know whether an entity represents a player, enemy, tree or projectile. It only cares that the entity contains both $transform and $sprite components.

Systems are isolated from one another. They do not directly own entities or depend on references to other systems. Systems uses a pub/sub system to communicate with each other.

Scenes#

A scene is a stage where entities and systems interact with each other to accomplish some aspect of your game. This can be a menu or a game level.

Scenes own their runtime state independently. Entities and systems belonging to one scene do not carry over to another. This keeps each scene self-contained and allows GameKit to initialize and dispose its resources as a single unit.

Next Steps#

Next, we'll explore components in more detail.