Features
Interactive demos showcasing bitECS-specific features. Each demonstrates a core API with a visual, runnable example.
Relationships
Entities follow their parents using relationships. Click to spawn children that orbit their parent.
// Create a relation
const ChildOf = createRelation()
// Create parent-child relationship
addComponent(world, child, ChildOf(parent))
// Query all children of a specific parent
const children = query(world, [ChildOf(parent)])
// Query all entities that are children of anything
const allChildren = query(world, [ChildOf('*')])
// Get the parent entity from a child
const [parent] = getRelationTargets(world, child, ChildOf)Prefabs
Entities inherit from prefab templates. Changing the prefab affects all instances. Click to spawn instances.
// Create a prefab (template)
const EnemyPrefab = addPrefab(world)
addComponent(world, EnemyPrefab, set(Health, { max: 100 }))
// Spawn instance that inherits from prefab
const enemy = addEntity(world)
addComponent(world, enemy, IsA(EnemyPrefab))
// Instance inherits Health.max = 100 from prefab
// Changing prefab's Health.max updates all instancesObservers
Visual feedback when components are added, removed, or changed. Watch entities react to component lifecycle events.
// React when component is added
observe(world, onAdd(Health), (eid) => {
spawnEffect(eid, 'green') // Visual feedback
})
// React when component changes
observe(world, onSet(Health), (eid, { current }) => {
if (current < 30) flashRed(eid)
})
// React when component is removed
observe(world, onRemove(Health), (eid) => {
spawnDeathParticles(eid)
})Query Operators
Filter entities with And, Or, Not operators. Toggle components to see how queries update in real-time.
// Or - match entities with either component
const targets = query(world, [Or(Player, Enemy)])
// Not - exclude entities with component
const active = query(world, [Position, Not(Frozen)])
// Combined operators
const threats = query(world, [
Or(Enemy, Projectile),
Position,
Not(Dead)
])Wildcard Queries
Query relationships without knowing the target. Find all entities that have any relationship of a type.
// Find all entities targeting anything
const allTargeting = query(world, [Targeting('*')])
// Find all entities that ARE targets of any Targeting relation
const allTargeted = query(world, [Wildcard(Targeting)])
// Find all children regardless of parent
const allChildren = query(world, [ChildOf('*')])
// Get what an entity is targeting
const targets = getRelationTargets(world, eid, Targeting)Exclusive Relations
Entities can only have one target per exclusive relation. Setting a new target removes the old one.
// Make a relation exclusive
const Targeting = createRelation(makeExclusive)
// Entity can only target one thing at a time
addComponent(world, enemy, Targeting(player1))
addComponent(world, enemy, Targeting(player2))
// Now enemy only targets player2 (player1 removed)
// Useful for: current target, equipped item,
// active state, selected unit, etc.