Drag 'n' Drop MovieClips / Box2D Bodies How To (*UPDATED*)

about the great mayo's work: can someobdy explain me how can i detect a body, shape or circle attribute from the contact of other one? if i have an object that has an event listener for contacts and is static, how can i know the attributes of the other object
jellyIam wrote:
about the great mayo's work: can someobdy explain me how can i detect a body, shape or circle attribute from the contact of other one? if i have an object that has an event listener for contacts and is static, how can i know the attributes of the other object


Take a look at the "Contact" class. This is the type of event that is dispatched via "addContact", etc. by the ContactListener. Here's some example code:

Code:
public function myAddContactListener(e:Contact) {
    e.freeze(); // This sets the contact up so everything is in the context of whatever shape your listening to.
    var otherShape:Shape = (e.shape2.GetUserData() as Shape); // after "freeze" shape2 will always point to the "other" shape.
    trace(otherShape.x); // Just traces the x value of the movieclip. You should be able to get other properties now.
    var s:MyCustomShapeClass = (otherShape as MyCustomShapeClass);
    if(s) s.doSomething(); // Detect a contact with a specific type of Shape you've subclassed.
}


That's just off the top of my head. May be syntax errors, but that's the idea.
hey mayobutter, thamks for the help, how would you make a shape count how many shapes or circles are above it? it's the only thing that bothers me.
Ok, this thread has gone on long enough. It's just a series of questions more or less unrelated to the original point, and poor mayo is diligently answering them all.

Open up a new topic if you have a question, but please, despite the ease of creating content using mayo's code, you still need to read the manual and understand a bit about how Box2D works if you want to progress further.

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