mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
2 KiB
2 KiB
First Jecs project
Now that you have installed Jecs, you can create your World.
:::code-group
local jecs = require(path/to/jecs)
local world = jecs.World.new()
import { World } from "@rbxts/jecs"
const world = new World()
:::
Let's create a couple components.
:::code-group
local jecs = require(path/to/jecs)
local world = jecs.World.new()
local Position = world:component()
local Velocity = world:component()
import { World } from "@rbxts/jecs"
const world = new World()
const Position = world.component()
const Velocity = world.component()
:::
Systems can be as simple as a query in a function or a more contextualized construct. Let's make a system that moves an entity and decelerates over time.
:::code-group
local jecs = require(path/to/jecs)
local world = jecs.World.new()
local Position = world:component()
local Velocity = world:component()
for id, position, velocity in world:query(Position, Velocity) do
world:set(id, Position, position += velocity)
world:set(id, Velocity, velocity * 0.9)
end
import { World } from "@rbxts/jecs"
const world = new World()
const Position = world.component()
const Velocity = world.component()
for (const [id, position, velocity] of world.query(Position, Velocity)) {
world.set(id, Position, position.add(velocity)
world.set(id, Velocity, velocity.mul(0.9))
}
:::
Where To Get Help
If you are encounting problems, there are resources for you to get help:
- Roblox OSS Discord server has a #jecs thread under the #projects channel
- Open an issue if you run into bugs or have feature requests
- Dive into the nitty gritty in the thesis paper