Skip to main content

ColliderComponent

Components are containers for state in Excalibur, the are meant to convey capabilities that an Entity possesses

Implementations of Component must have a zero-arg constructor to support dependencies

class MyComponent extends ex.Component {
  // zero arg support required if you want to use component dependencies
  constructor(public optionalPos?: ex.Vector) {}
}

Hierarchy

Index

Constructors

constructor

Properties

public$colliderAdded

$colliderAdded: Observable<Collider> = ...

Observable that notifies when a collider is added to the body

public$colliderRemoved

$colliderRemoved: Observable<Collider> = ...

Observable that notifies when a collider is removed from the body

optionalreadonlydependencies

dependencies?: ComponentCtor<Component>[]

Optionally list any component types this component depends on If the owner entity does not have these components, new components will be added to the entity

Only components with zero-arg constructors are supported as automatic component dependencies

publicevents

events: EventEmitter<any> = ...

optionalowner

owner?: Entity<any> = undefined

Current owning [[Entity]], if any, of this component. Null if not added to any [[Entity]]

Accessors

publicbounds

publiclocalBounds

Methods

publicclear

  • clear(): void
  • Remove collider geometry from collider component


    Returns void

publicclone

  • Clones any properties on this component, if that property value has a clone() method it will be called


    Returns ColliderComponent

collide

publicget

  • Get the current collider geometry


    Returns Collider

onAdd

  • onAdd(entity: Entity<any>): void
  • Optional callback called when a component is added to an entity


    Parameters

    Returns void

onRemove

  • onRemove(): void
  • Optional callback called when a component is removed from an entity


    Returns void

publicprocessColliderRemoval

  • processColliderRemoval(): void
  • Returns void

publicset

  • set<T>(collider: T): T
  • Set the collider geometry


    Type parameters

    Parameters

    • collider: T

    Returns T

    the collider you set

publicupdate

  • update(): void
  • Update the collider's transformed geometry


    Returns void

useBoxCollider

  • Sets up a box geometry based on the current bounds of the associated actor of this physics body.

    If no width/height are specified the body will attempt to use the associated actor's width/height.

    By default, the box is center is at (0, 0) which means it is centered around the actors anchor.


    Parameters

    • width: number
    • height: number
    • anchor: Vector = Vector.Half
    • center: Vector = Vector.Zero

    Returns PolygonCollider

useCircleCollider

  • Sets up a [[Circle|circle collision geometry]] as the only collider with a specified radius in pixels.

    By default, the box is center is at (0, 0) which means it is centered around the actors anchor.


    Parameters

    • radius: number
    • center: Vector = Vector.Zero

    Returns CircleCollider

useCompositeCollider

  • Setups up a [[CompositeCollider]] which can define any arbitrary set of excalibur colliders


    Parameters

    Returns CompositeCollider

useEdgeCollider

  • Sets up an [[Edge|edge collision geometry]] with a start point and an end point relative to the anchor of the associated actor of this physics body.

    By default, the box is center is at (0, 0) which means it is centered around the actors anchor.


    Parameters

    Returns EdgeCollider

usePolygonCollider

  • Sets up a [[PolygonCollider|polygon]] collision geometry based on a list of of points relative to the anchor of the associated actor of this physics body.

    Only convex polygon definitions are supported.

    By default, the box is center is at (0, 0) which means it is centered around the actors anchor.


    Parameters

    Returns PolygonCollider