jecs/docs/learn/overview/first-jecs-project.md
ChinoUkaegbu 46f99a5e2b
Fix typos in docs (#151)
* fix typos in docs

* Update component-traits.md
2024-11-17 21:05:20 +01:00

2.1 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 encountering problems, there are resources for you to get help: