The ECS world type (e.g. ECSpresso<C, E, R>). Defaults to unknown.
Union of valid layer names. Defaults to string.
Provide specific layer names for compile-time key validation:
createCollisionPairHandler<ECS, keyof typeof layers>({...})
Object mapping "layerA:layerB" keys to callbacks
A dispatch function to call with collision event data and ECS instance
// Basic usage:
const handler = createCollisionPairHandler<ECS>({
'playerProjectile:enemy': (projectileId, enemyId, ecs) => {
ecs.commands.removeEntity(projectileId);
},
});
// With layer name validation:
const layers = defineCollisionLayers({ player: ['enemy'], enemy: ['player'] });
type Layer = LayersOf<typeof layers>;
const handler = createCollisionPairHandler<ECS, Layer>({
'player:enemy': (playerId, enemyId, ecs) => { ... },
});
ecs.eventBus.subscribe('collision', (data) => handler({ data, ecs }));
Create a collision pair handler that routes collision events to layer-pair-specific callbacks.
Registering
"a:b"automatically handles both(layerA=a, layerB=b)and(layerA=b, layerB=a). Entity arguments are swapped to match the declared key order. If both"a:b"and"b:a"are explicitly registered, each gets its own handler with no implicit reverse.