I’m playing around with box2djs. I’m trying to find a way to write an ‘onCollision()’ callback function, but the documentation is sparse and I can’t find an obvious way to do it.
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Call back for box2djs is actually referenced as a collision “filter.” Here is how you can implement it. I’ll also show what I’m doing instead which maybe is a little slower but since my other approach is outside the step() I can destroy objects and stuff:
probably not as nice as a true callback, but I had originally had trouble trying to get a callback to work so I wrote this approach and ended up keeping it instead. I do this in my main loop that calls the world.step()
documentation is pretty much unavailable from what I found, but I really like box2djs and have finally figured out everything I need to accomplish some simple hobby projects. Here are some examples that extend the original box2djs demo jellyrobotics box2djs project