mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Close code groups
This commit is contained in:
parent
5d05e5ae5d
commit
bd28e887c3
1 changed files with 8 additions and 2 deletions
|
@ -23,7 +23,8 @@ Operation | Description
|
||||||
|
|
||||||
In an ECS, components need to be uniquely identified. In Jecs this is done by making each component is its own unique entity. If a game has a component Position and Velocity, there will be two entities, one for each component. Component entities can be distinguished from "regular" entities as they have a `Component` component. An example:
|
In an ECS, components need to be uniquely identified. In Jecs this is done by making each component is its own unique entity. If a game has a component Position and Velocity, there will be two entities, one for each component. Component entities can be distinguished from "regular" entities as they have a `Component` component. An example:
|
||||||
|
|
||||||
:::code-group
|
::: code-group
|
||||||
|
|
||||||
```luau [luau]
|
```luau [luau]
|
||||||
local Position = world:component() :: jecs.Entity<Vector3>
|
local Position = world:component() :: jecs.Entity<Vector3>
|
||||||
print(world:has(Position, Jecs.Component))
|
print(world:has(Position, Jecs.Component))
|
||||||
|
@ -34,9 +35,12 @@ const Position = world.component<Vector3>();
|
||||||
print(world.has(Position, Jecs.Component))
|
print(world.has(Position, Jecs.Component))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
All of the APIs that apply to regular entities also apply to component entities. This means it is possible to contexualize components with logic by adding traits to components
|
All of the APIs that apply to regular entities also apply to component entities. This means it is possible to contexualize components with logic by adding traits to components
|
||||||
|
|
||||||
:::code-group
|
::: code-group
|
||||||
|
|
||||||
```luau [luau]
|
```luau [luau]
|
||||||
local Networked = world:component()
|
local Networked = world:component()
|
||||||
local Type = world:component()
|
local Type = world:component()
|
||||||
|
@ -107,3 +111,5 @@ for (const [id, ty, name] of world.query(Type, Name).with(Networked)) {
|
||||||
updatePositions.FireServer(packet)
|
updatePositions.FireServer(packet)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
Loading…
Reference in a new issue