thanks for your answers mayo, another thing that bothers me is that i can´t succesfully add a new polygonal shape of my own, drawing it in the stage, i apply the Get Points.jsfl to my figure on stage and it works but when i run everything my figure always does strange patterns, i can grab it but still it behaves oddly, i´ve been looking to the output that DemoPoly uses and i´ve noticed the x and y values differ rather constantly between negative and postive values, however my polygon output throws only positive x and y's, [[[426.95, 216], [426.95, 284], [307.95, 216]], [[399.95, 132], [307.95, 172], [117, 41], [321.95, 51]], [[307.95, 172], [307.95, 216], [191, 173], [117, 41]], [[307.95, 216], [426.95, 284], [96, 284], [191, 173]]] , is that normal?! Anyway i can´t qet a polygon of my own to work.
Drag 'n' Drop MovieClips / Box2D Bodies How To (*UPDATED*)
FlashProbably the reason all of your values are positive is that your shape is drawn entirely in the +x +y region. Try centering it at 0,0.
What do you mean by "strange patterns?"
When you run the jsfl, it should trace the decomposition with red lines. This represents the polygon "break down". Do the polygon's look correct?
What do you mean by "strange patterns?"
When you run the jsfl, it should trace the decomposition with red lines. This represents the polygon "break down". Do the polygon's look correct?
i've tried drawing the figure in different regions to see if the values change but they remain the same, i´ll try to center it to discard that possibility, but is that the only thing i´m doing wrong? the outlines when i use the get Points do seem to be right. i do have to make a new class copying the script in DemoPoly, changing the class name, copying my figure's new x,y values and saving it to the wck folder, then make a movieclip out of my figure with the wck."figureClass", then make it a wck."figureClass" component don´t i? also do you know any way to manage two different layers in which the bodies in one layer do have contact among them, but the bodies in the other layer do not respond to the bodies in the first one but only among them? sort of a way to add deepness between box2d objects? excuse me if i am abusing a little bit with my questions.
That all sounds correct - if you send me a .fla I can take a closer look.
Regarding the layers - you can use the shapeCategoryBits, shapeMaskBits and shapeGroupIndex properties to simulate that. See this section of the manual for more info.
Regarding the layers - you can use the shapeCategoryBits, shapeMaskBits and shapeGroupIndex properties to simulate that. See this section of the manual for more info.
thanks mayo, i've solved my figure problem, and thanks for the link
can somebody post an example about triggering events when a movieclip with gravity and all touches another one? or when the movieclip crosses over other one?
hey mayo,do you know how to instantiate new movieclips with box2d properties into a specific position in an already created world?
hey mayo,do you know how to instantiate new movieclips with box2d properties into a specific position in an already created world?
What is the correct way to invoke the ContactListener? I'd appreciate any help:
If I go:
Then
... I get a 'possibly undefined method' error. What am I doing wrong?
If I go:
Code:
world.addEventListener(ContactListener.Add(), contactFunction);
Then
Code:
public function contactFunction(e:Contact):void{
var temp = e.cp.shape1.GetUserData();
trace(temp.name);
}
var temp = e.cp.shape1.GetUserData();
trace(temp.name);
}
... I get a 'possibly undefined method' error. What am I doing wrong?
I added a new object to the first demo that demonstrates responding to collisions. It just plays an animation when a new contact point is added. You can re-download the source if you'd like, but it's really dead simple:
I'll come up with something fancier later, but that's the basic idea.
EDIT: Ok, I added another symbol, "DemoCollider2", that demonstrates basic usage of the ContactList class.
Code:
public class DemoCollider extends Circle {
public function DemoCollider() {
addEventListener('addContact', contactAdded, false, 0, true);
}
public function contactAdded(e:Event):void {
gotoAndPlay(2);
}
}
public function DemoCollider() {
addEventListener('addContact', contactAdded, false, 0, true);
}
public function contactAdded(e:Event):void {
gotoAndPlay(2);
}
}
I'll come up with something fancier later, but that's the basic idea.
EDIT: Ok, I added another symbol, "DemoCollider2", that demonstrates basic usage of the ContactList class.
hey mayo,do you know how to instantiate new movieclips with box2d properties into a specific position in an already created world?
when a body collides with another or some other event?
when a body collides with another or some other event?
Thanks mayo. I was going to ask you how you run this listener from the base class, but this way is more useful.
Original thread: https://box2d.org/forum/viewtopic.php?t=367