|
1 |
| -## TODO |
| 1 | +# First Jecs project |
2 | 2 |
|
3 |
| -This is a TODO stub. |
| 3 | +Now that you have installed Jecs, you can create your [World](world.md). |
| 4 | + |
| 5 | +:::code-group |
| 6 | +```luau [luau] |
| 7 | +local jecs = require(path/to/jecs) |
| 8 | +local world = jecs.World.new() |
| 9 | +``` |
| 10 | +```typescript [typescript] |
| 11 | +import { World } from "@rbxts/jecs" |
| 12 | +const world = new World() |
| 13 | +``` |
| 14 | +::: |
| 15 | + |
| 16 | +Let's create a couple components. |
| 17 | + |
| 18 | +:::code-group |
| 19 | +```luau [luau] |
| 20 | +local jecs = require(path/to/jecs) |
| 21 | +local world = jecs.World.new() |
| 22 | +
|
| 23 | +local Position = world:component() |
| 24 | +local Velocity = world:component() |
| 25 | +``` |
| 26 | + |
| 27 | +```typescript [typescript] |
| 28 | +import { World } from "@rbxts/jecs" |
| 29 | +const world = new World() |
| 30 | + |
| 31 | +const Position = world.component() |
| 32 | +const Velocity = world.component() |
| 33 | +``` |
| 34 | +::: |
| 35 | + |
| 36 | +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. |
| 37 | + |
| 38 | +:::code-group |
| 39 | +```luau [luau] |
| 40 | +local jecs = require(path/to/jecs) |
| 41 | +local world = jecs.World.new() |
| 42 | +
|
| 43 | +local Position = world:component() |
| 44 | +local Velocity = world:component() |
| 45 | +
|
| 46 | +for id, position, velocity in world:query(Position, Velocity) do |
| 47 | + world:set(id, Position, position += velocity) |
| 48 | + world:set(id, Velocity, velocity * 0.9) |
| 49 | +end |
| 50 | +``` |
| 51 | + |
| 52 | +```typescript [typescript] |
| 53 | +import { World } from "@rbxts/jecs" |
| 54 | +const world = new World() |
| 55 | + |
| 56 | +const Position = world.component() |
| 57 | +const Velocity = world.component() |
| 58 | + |
| 59 | +for (const [id, position, velocity] of world.query(Position, Velocity)) { |
| 60 | + world.set(id, Position, position.add(velocity) |
| 61 | + world.set(id, Velocity, velocity.mul(0.9)) |
| 62 | +} |
| 63 | +``` |
| 64 | +::: |
| 65 | +
|
| 66 | +## Where To Get Help |
| 67 | +
|
| 68 | +If you are encounting problems, there are resources for you to get help: |
| 69 | +- [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 |
| 70 | +- [Open an issue](https://github.com/ukendio/jecs/issues) if you run into bugs or have feature requests |
| 71 | +- Dive into the nitty gritty in the [thesis paper](https://raw.githubusercontent.com/Ukendio/jecs/main/thesis/drafts/1/paper.pdf) |
0 commit comments