The Collision object

When Hitbox detects a collision between two elements, it calls the user-defined functions, giving them a Collision object as parameter. This object has many useful properties

elements

Type

array

An array containing the 2 elements concerned by the collision

element

Type

Node

One of the two elements concerned by the collision.

If you provided the targetElements parameter to the constructor, this element will be from the set of elements you provided with the elements parameter.

targetElement

Type

Node

The other element concerned by the collision.

If you provided the targetElements parameter to the constructor, this element will be from the set of elements you provided with the targetElements parameter.

overlap

Type

number

A number between 0 and 1 representing the amount of overlap between the two elements (0 is no collision and 1 is when an element completely overlaps the other)

overlap = 0

overlap = 0.36

overlap = 1

top

Type

number

The distance from the top of the viewport of the colliding area.

left

Type

number

The distance from the left of the viewport of the colliding area.

width

Type

number

The width of the colliding area.

height

Type

number

The width of the colliding area.

area

Type

number

The area in px² of the colliding area.

Last updated

Was this helpful?