Strata - v1.4.10
    Preparing search index...

    Function createSystem

    • Creates a simple system function from a query and update function.

      Helper for creating systems that iterate over entities with specific components. Reduces boilerplate for common system patterns.

      Type Parameters

      Parameters

      • components: (keyof T)[]

        Component keys to query for.

      • update: (entity: T, deltaTime: number) => void

        Function to call for each matching entity.

      Returns SystemFn<T>

      A SystemFn that can be registered with the scheduler.

      // Movement system using createSystem helper
      const movementSystem = createSystem(
      ['position', 'velocity'],
      (entity, dt) => {
      entity.position.x += entity.velocity.x * dt;
      entity.position.y += entity.velocity.y * dt;
      entity.position.z += entity.velocity.z * dt;
      }
      );

      scheduler.register({
      name: 'movement',
      fn: movementSystem,
      priority: 10
      });
      // Health decay system
      const decaySystem = createSystem(['health'], (entity, dt) => {
      entity.health -= 1 * dt;
      if (entity.health <= 0) {
      // Mark for removal
      entity.dead = true;
      }
      });