Options
All
  • Public
  • Public/Protected
  • All
Menu

@bendiksolheim/ecs

Index

Type aliases

Filter

Filter: {}

A Filter is the constructor of a Component A Filter is the constructor of a Component

Type declaration

Functions

logicSystem

  • logicSystem(filter: Filters, tick: (entities: Record<keyof typeof filter, Entity[]>, world: World) => void): LogicSystem
  • Initializer for a logic system. A logic system performs some kind of game logic in your game, e.g. checks for collission. A logic system is executed N times per frame depending on what you set your FPS to be. An FPS value of 60 means it is executed on average once per frame, while an FPS value of 120 will execute it twice. Usage:

    const logicSystem = logicystem(
        { myEntities: [ComponentOne, ComponentTwo] },
        (entities: Record<string, Entity[]>, world: World) => {
            entities.myEntities.forEach(entity => {
                console.log(entity.has(ComponentOne)); // -> true
                console.log(entity.has(ComponentTwo)); // -> true
            });
        }
    );

    Parameters

    • filter: Filters
    • tick: (entities: Record<keyof typeof filter, Entity[]>, world: World) => void
        • (entities: Record<keyof typeof filter, Entity[]>, world: World): void
        • Parameters

          • entities: Record<keyof typeof filter, Entity[]>
          • world: World

          Returns void

    Returns LogicSystem

renderSystem

  • renderSystem(filter: Filters, tick: (entities: Record<keyof typeof filter, Entity[]>, lag: number, world: World) => void): RenderSystem
  • Initializer for a render system. A render system performs some kind of rendering in your game. Where a logic system may be run N times per game frame, a render system will always be executed exactly once, and always after every logic system. A render system should ideally not calculate stuff, only perform rendering.

    A render system is passed a lag parameter. This parameter tells how "far into" the frame you are. It is a value between 0 (start of frame) and 1 (end of frame). This can be used to compensate for the time your logic systems has spent during a frame.

    const renderSystem = renderSystem(
        { renderable: [Renderable] },
        (entities: Record<string, Entity[]>, lag: number, world: World) {
            entities.renderable.forEach(entity => {
                console.log(entity.has(Renderable)); // -> true
            })
        }
    )

    Parameters

    • filter: Filters
    • tick: (entities: Record<keyof typeof filter, Entity[]>, lag: number, world: World) => void
        • (entities: Record<keyof typeof filter, Entity[]>, lag: number, world: World): void
        • Parameters

          • entities: Record<keyof typeof filter, Entity[]>
          • lag: number
          • world: World

          Returns void

    Returns RenderSystem

Generated using TypeDoc