jecs/docs/learn/overview/first-jecs-project.md

75 lines
2.1 KiB
Markdown
Raw Normal View History

2024-07-31 02:16:28 +00:00
# First Jecs project
2024-07-31 03:07:23 +00:00
Now that you have installed Jecs, you can create your [World](https://ukendio.github.io/jecs/api/world.html).
2024-07-31 02:16:28 +00:00
:::code-group
```luau [luau]
local jecs = require(path/to/jecs)
local world = jecs.World.new()
```
```typescript [typescript]
import { World } from "@rbxts/jecs"
const world = new World()
```
:::
Let's create a couple components.
:::code-group
```luau [luau]
local jecs = require(path/to/jecs)
local world = jecs.World.new()
local Position = world:component()
local Velocity = world:component()
```
```typescript [typescript]
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
```luau [luau]
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
2024-09-16 20:16:50 +00:00
world:set(id, Position, position + velocity)
2024-07-31 02:16:28 +00:00
world:set(id, Velocity, velocity * 0.9)
end
```
```typescript [typescript]
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)) {
2024-09-16 20:16:50 +00:00
world.set(id, Position, position.add(velocity))
2024-07-31 02:16:28 +00:00
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:
2024-07-31 02:16:28 +00:00
- [Roblox OSS Discord server](https://discord.gg/h2NV8PqhAD) has a [#jecs](https://discord.com/channels/385151591524597761/1248734074940559511) thread under the [#projects](https://discord.com/channels/385151591524597761/1019724676265676930) channel
- [Open an issue](https://github.com/ukendio/jecs/issues) if you run into bugs or have feature requests
- Dive into the nitty gritty in the [thesis paper](https://raw.githubusercontent.com/Ukendio/jecs/main/thesis/drafts/1/paper.pdf)
2025-03-23 17:59:24 +00:00
## Benefits
Jecs immediately adds 500k players to your game.