I have various bodies rotated at some angle with the help of Box2d in libGDX. What I want is to destroy the body when I click on it, but the problem is that I am not able to get the area definition of the body so that I can check whether my touch point lies inside the body. I tried using actor and its hit() method but it's working only if I don't rotate it, As far as I know, once I rotate the body, its bounds are not rotated. How can I check the Touch event in a Body?
Tell me more
×
Game Development Stack Exchange is a question and answer site for
professional and independent game developers. It's 100% free, no registration required.
|
|
You could assign a sprite to your box2d body. Form example I created a circle dynamic body with a radius of 1f, than I assigned to it a sprite (a red ball) that fits exactly the box2d body. Now it simply checks if the touch lies into sprite width and height. Example Code:
|
|||
|
|
|
Create Box2d fixture for your touch (and attach it to body), set it to be a sensor, place it where your touch event occurred. From now on, you can check every body that collides with your sensor. And because you are using sensor, simulation will not respond to such collision(s), but will report them instead. Here's Box2d manual, look at chapter 6.3 about sensors. |
|||
|
|
