Skip to content

A Matter.js plugin for adding per-body collision events and event handlers.

License

Notifications You must be signed in to change notification settings

dxu/matter-collision-events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

matter-collision-events

matter-collision-events is a Matter.js plugin that adds per-body collision events.

Installing

npm install matter-collision-events

Usage

Refer to the official guide on using plugins for step-by-step instructions. matter-collision-events can be included in the browser or imported via modules.

You can call Matter.use('matter-collision-events') to install the plugin itself for usage.

This plugin triggers three new events on Matter.Body:

  1. onCollide
  2. onCollideEnd
  3. onCollideActive

These events correspond to the Matter.js events collisionStart, collisionActive, and collisionEnd, respectively. You can listen to these events via Matter.Events.

This plugin also extends Matter.Body with three convenience functions:

  1. Matter.Body.onCollide(callback)
  2. Matter.Body.onCollideEnd(callback)
  3. Matter.Body.onCollideActive(callback)

You can register event callbacks by providing a function of type ( pair: Matter.Pair) => void:

Example usage can be found under the docs folder, which contains a basic example of its usage.

Demo

View the demo here.

License

MIT

About

A Matter.js plugin for adding per-body collision events and event handlers.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published