New on WCK

Hi everyone, I will start by letting you know that i am new on Box2D, nevertheless I working hard to understand well the tool. I studied animation and now I am studying software development to complement my skill on game development, my goal is to, someday work on the gaming industry, since I am one of those guys that don’t want to wait to finish school to get the hands dirty on the job I already dig into flash and I think I like it a lot.

This is my question; I am using the WCK to create a game. The problem I am having is on the game logic. It’s kind of breaking my head, so I decided to look for help. Does anyone here can help figure this out. Let’s say that you have two balls and when one of those ball collides the other one a collision should be detected to trigger something, where or how can I do this on the WCK?
Any information will be very appreciated
Thank you.
EPadilla
PreSolve then BeginContact
you can setup a listener for either of those, there are examples in the demo classes, i believe boxMan.as has one.

you also need to set the wck body to send those contact events, usually done through the ComponentInspector.

hope this helps, if you need more detail let me know.
Thank a lot for replying so quickly sketchbookgames.
I will take a very good look to the demo files and then let you know what I find.
EPadilla
If you look in Boxman.as, this line is similar to addEventListener and calls the function handleContact once a physical object collides with the boxman

Code:
         listenWhileVisible(this, ContactEvent.BEGIN_CONTACT, handleContact);


Then in the function handleContact, the e:ContactEvent is an event that stores info about the colliding object.
In this case, the data of the e:ContactEvent is accessed via e.other.m_userData and then there's a check wether the colliding object is a Pellet.


Code:
      public function handleContact(e:ContactEvent):void {
         var p:Pellet = e.other.m_userData as Pellet;
         if(p) {
            Util.addChildAtPosOf(world, new FX1(), p); 
            p.remove();
         }
      }



Alternatively you could also access the colliding object via e.relatedObject, for example
Code:
      public function handleContact(e:ContactEvent):void {
                       if (e.relatedObject == myCollidingObject) {
                       do something
                       }
}


I've saw somehere that the e.relatedObject is not as safe to use, but i cant remember where. I use it and for me it works fine.
Cheers
Thank a lot guys, I really appreciate the help, I didn’t know that I was going to be replied on this so quickly, unfortunately I haven’t got time to sit down and continue my game due to school projects. I soon as I get the chance I continue working on it, I will keep the post update.

Thanks again
EPadilla
I got to start saying that you guys are awesome! 😀

I couldn’t wait to try your instructions and this morning without doing much work I was able to get the trace telling me about the collision. I really appreciate you help and I am very, very amazed how good this forum is.
Thank you very much Frnk and sketchbookgames for your help. I hope someday I can be as helpful to someone on this forum as you guys have been to me.

I will see you around and as soon as I get my game online I will let you know.
I guess I can close the topic now.
EPadilla

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