jecs/docs/learn/overview/first-jecs-project.md
2024-07-31 05:04:53 +02:00

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: