jecs/docs/api/world.md
2024-07-26 04:36:30 +02:00

1,003 B

World

A World contains entities which have components. The World is queryable and can be used to get entities with a specific set of components.

Functions

new()

function World.new(): World

Creates a new world.

Example: ::: code-group

local world = jecs.World.new()
import { World } from "@rbxts/jecs";

const world = new World();

:::

entity()

function World:entity(): Entity

Creates a new entity.

Example: ::: code-group

local entity = world:entity()
const entity = world.entity();

:::

component()`

function World:component<T>(): Entity<T>

Creates a new component.

Example: ::: code-group

local Health = world:component() :: jecs.Entity<number>
const Health = world.component<number>();

:::

::: info You should use this when creating components.

For example, a Health type should be created using this. :::