PhysicsHitbox

View source

Provides an ECS component for an entity’s 2D world-space axis-aligned bounds. Use PhysicsHitbox when broadphase collision or spatial queries need the entity’s current bounds. It extends BoundingBox2D and stores the lower and upper coordinates in its inherited min and max vectors.

Examples

import { Query, World } from '@wimaengine/ecs'
import { PhysicsHitbox } from '@wimaengine/broadphase'

const world = new World()
world.spawn([new PhysicsHitbox(-1, -1, 1, 1)])

new Query(world, [PhysicsHitbox]).each(([hitbox]) => {
  // These values reflect the collider's current world-space bounds.
  console.log(hitbox.min.x, hitbox.min.y, hitbox.max.x, hitbox.max.y)
})

Constructor


constructor(minX?: number, minY?: number, maxX?: number, maxY?: number)

View source

Creates a 2D axis-aligned bounding box.

The constructor stores the supplied coordinates directly: minX and minY initialize BoundingBox2D#min, while maxX and maxY initialize BoundingBox2D#max. All four coordinates default to 0; the constructor does not reorder them or enforce that min is below max.

Parameters

NameDescriptionDefault
minX?

Lower x coordinate.

0
minY?

Lower y coordinate.

0
maxX?

Upper x coordinate.

0
maxY?

Upper y coordinate.

0

Methods


staticcopy(source: PhysicsHitbox, target?: PhysicsHitbox): PhysicsHitbox

View source

Copies the coordinates of a box into an output box.

Only the min and max coordinates are copied. The source is not modified, and out defaults to a new BoundingBox2D.

Parameters

NameDescriptionDefault
source

Hitbox to copy.

—
target?

Hitbox to populate.

...

Returns

The output box.

staticclone(target: PhysicsHitbox): PhysicsHitbox

View source

Creates an independent hitbox with the same bound coordinates.

Parameters

NameDescriptionDefault
target

Hitbox to clone.

—

Returns

A new hitbox containing the source coordinates.

staticserialize(value: PhysicsHitbox): object

View source

Serializes a box to its plain coordinate representation.

The result contains max and min vector data. It does not include the runtime type field.

Parameters

NameDescriptionDefault
value

Hitbox to serialize.

—

Returns

Serialized coordinate data.

staticdeserialize(value: BoundingBox2DSerial, out?: PhysicsHitbox): PhysicsHitbox

View source

Restores box coordinates from serialized data.

max and min are written into the supplied output, or into a new box when out is omitted. Any serialized type property is ignored.

Parameters

NameDescriptionDefault
value

Serialized bound coordinates.

—
out?

Hitbox to populate.

...

Returns

The restored output box.