Published
Edited
Sep 4, 2021
1 fork
Insert cell
Insert cell
Insert cell
## Code
---
Insert cell
bitecs = require('https://bundle.run/bitecs@0.3.12')
Insert cell
{
const world = bitecs.createWorld()
world.name = "MyWorld"

const eid = bitecs.addEntity(world);
const eid2 = bitecs.addEntity(world);
bitecs.removeEntity(world, eid2)

const Vector3 = { x: bitecs.Types.f32, y: bitecs.Types.f32, z: bitecs.Types.f32 }
const Position = bitecs.defineComponent(Vector3)
const Velocity = bitecs.defineComponent(Vector3)
const List = bitecs.defineComponent({ values: [bitecs.Types.f32, 3] }) // [type, length]
const Tag = bitecs.defineComponent()

bitecs.addComponent(world, Position, eid)
bitecs.addComponent(world, Velocity, eid)
bitecs.addComponent(world, List, eid)
bitecs.addComponent(world, Tag, eid)

Velocity.x[eid] = 1
Velocity.y[eid] = 1

List.values[eid].set([1,2,3])
const movementQuery = bitecs.defineQuery([Position, Velocity])
const ents = movementQuery(world)
const positionWithoutVelocityQuery = bitecs.defineQuery([ Position, bitecs.Not(Velocity) ])
const changedPositionQuery = bitecs.defineQuery([ bitecs.Changed(Position) ])

let entspos1 = changedPositionQuery(world)
console.log(entspos1) // => []

Position.x[eid]++

let entspos2 = changedPositionQuery(world)
console.log(entspos2) // => [0]
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more