Skip to content

@vaguevoid/fiasco / ecs/components / BoxCollider

Type Alias: BoxCollider

BoxCollider = Component

Defined in: src/ecs/components.ts:627

A component for detecting 2D collisions with other BoxColliders.

Attach this component to any entity and get notified if it collides via events.

ts
import { Query, Transform, BoxCollider, SystemOnce, EventReader, Events } from '@vaguevoid/fiasco'
import { Components } from '../.fiasco/generated'

function system(): SystemOnce {
  engine.spawn([
    new Components.Camera(),
    new Components.Transform(),
    new Components.BoxCollider()
  ])
}

function system2(collisions: EventReader<Events.Physics.BoxCollision>) {
  for (const collision of collisions) {
    // despawn anything that collides
    engine.despawn(collision.entities(0)!)
    engine.despawn(collision.entities(1)!)
  }
}