This project has moved. For the latest updates, please go here.

how to check if the player make a CLICK on a Body?

Topics: Developer Forum, User Forum
Jul 14, 2012 at 12:09 PM

how can i get a click event on a body with farseer?

(it does not mater if it is click or hold)

Jul 15, 2012 at 9:21 PM

Check how it's done in the TestBed for an example.

First you need to get the mouse position in World Coordinates based on your view and projection matrices (the testbed has a helper method, so does the Camera class in the Samples).

Then you create an AABB centered at the mouse. Set the dimensions the way you want based on some heuristic for example small for a mouse click, larger for touch etc. This will affect the precision.

Do World.QueryAABB() to find out the fixtures overlapping the AABB. If you want super-precise spatial query do Fixture.TestPoint() after with the exact mouse position. Could be useful, though, to allow some imprecision for easier grabbing of objects.

Finally get the body from the fixture.

Jul 16, 2012 at 1:20 PM

You can also use World.TestPoint() which returns a Fixture. Remember if your using screen coordinates to convert them to Farseer units before passing them to TestPoint().