This example demonstrates the core concepts of jecs: creating a world, defining components, spawning entities, and querying them in a system.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Ukendio/jecs/llms.txt
Use this file to discover all available pages before exploring further.
Core Concepts
jecs follows the Entity Component System (ECS) pattern:- Entities are unique identifiers
- Components are data containers
- Systems are functions that query and process entities with specific components
Complete Example
Here’s a complete example showing how to create entities with Position and Velocity components, then update their positions in a query:Breaking It Down
Creating the World and Components
world:component() and act as type identifiers.
Spawning Entities
world:entity() and components are attached using world:set(entity, component, value).
Querying Entities
The query
world:query(Position, Velocity) only matches entities that have both components. Entity e3 is excluded because it only has Position.Key Takeaways
- Use
world:component()to define component types - Use
world:entity()to create entities - Use
world:set(entity, component, value)to attach components - Use
world:query(...)to iterate entities with specific components - Queries only match entities with all specified components
Next Steps
Networking
Learn client-server replication patterns for multiplayer games
Spatial Systems
Implement efficient spatial queries using voxel grids