Matter-js: Get the current coordinates of a body

Created on 3 Mar 2017  路  2Comments  路  Source: liabru/matter-js

I'm wondering if there's a way to get the current x/y coordinates of a body when the mouse is clicked.

What I need to do is have the matter.js bodies be clickable, while retaining mouse interactivity for the element below the canvas. The idea I have is to set pointer-events: none; on the canvas, then whenever the parent element is clicked, check if the mouse position is within the bounds of an existing body (and modify the body's size if so).

Does this sound possible?

question

Most helpful comment

You could do this using Query.point giving a mouse position and Composite.allBodies(engine.world). This will give you a list of bodies under the mouse, which you can then consult their body.position vectors.

All 2 comments

You can get the postion of a body with body.position.x and body.position.y. However I don't know how to get the width and height of a body.

You could do this using Query.point giving a mouse position and Composite.allBodies(engine.world). This will give you a list of bodies under the mouse, which you can then consult their body.position vectors.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jack-guy picture jack-guy  路  3Comments

TimuJiang picture TimuJiang  路  4Comments

kunchenguid picture kunchenguid  路  3Comments

Titozzz picture Titozzz  路  4Comments

liabru picture liabru  路  3Comments