How do i use sensors?

This is really basic, but i cant figure it out.

How do i respond to sensors?

I have a ball and some walls. I can get contact events when a ball hits a wall. So next i tried to make a sensor but i cant figure how to listen for these in a similar way. I have set isSensor to true on the sensor shape, and i have also set report begin/end to true.

Thanks
sounds like it should be working, all i can say is make sure you are listening for BEGIN_CONTACT, beyond that i would need to see the relevant part of your code and know the version.
"StickySand" extended MovieClip when it should have extended shapes.Box

😳

Thanks mate, if you hadnt replied id still be trying with ContactLists etc.
Final question on sensors!

So i read in the wiki that you can create a BodyShape from several other BodyShapes.

So for example take 4 box shapes:

[][][][]

I want to wrap these into a bigger BodyShape

([][][][])

And i want to use this shape as a sensor... Not the individual boxes.

Right now, ContactEvents* are generated

-----(*[]*[]*[]*[]*)--------->

But actually, im trying to get this:

-----*([][][][])*--------->

I cant figure what happens to BodyShapes when they are inside another BodyShape.

Any ideas?
set your box shapes to isGuideShape=true;
this should tell your shapes to use the same settings as your body, rather than being independent.

also if you are looking for a body when you receive the event. I do something like this

Code:
private function beginContact(ce:ContactEvent){
   var otherShape:* = ce.other.m_userData; //your []
   var otherBody:* = otherShape.body;//your ([][][][])


otherShape could be a shape or a body.
otherShape.body will always return the body.

i don't recall why i cast the type as *
BodyShape should be a safe assumption for both variables but something must have conflicted with it at some point.
Thanks again Sketchbook!

Im this very second going to check it out. 😀
You're still going to get a bunch of unwanted contact events though. No way around that. I would keep track of the number of persistant contacts like so:

beginContact - increment counter
endContact - decrement counter

as long as your counter is above zero you know they are touching.

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