How to know if touch is inside shape?

Hi!

Trying to implement detecting touch inside game elements and don't know how to make it.

I need at least two functions: detecting touch inside the shape (returns bool), checking the distance between touch and the shape (returns float).

I suppose that i can do it with Cocos2D using its own functions (checking sprite) or even creating CGPath and then check if the point is inside it but may be better to use Box2D shapes?

Any suggestions?
Found one..

Code: Select all

    if (hero.fixture->TestPoint(currentTouchLocationB2D)) {
...
    }


where hero.fixture is stored fixture. I have only one fixture for now, what if there are several?
currentTouchLocationB2D - converted touch location

UPD:

Yep. The magic word is "You can iterate over a body's fixtures." =) So i do not need to store it separately.

But the question about touch point and distance to the shape? What is the best way?
The section "4.12 Distance" in the manual looks like a good place to start.
http://box2d.org/manual.html

Original thread: https://box2d.org/forum/viewtopic.php?t=7736