flame icon indicating copy to clipboard operation
flame copied to clipboard

collision

Open glennmichaelmejias opened this issue 6 years ago • 6 comments

how to detect collision in box2d component? not just box collision,

glennmichaelmejias avatar Apr 30 '20 12:04 glennmichaelmejias

if you want to detect collision of a specific body i know you can do something like:

ContactEdge contact = body.getContactList();
while (contact != null) {
  contact = contact.next();
}

I also know that there's a ContactListener but haven't found any documentation or way to use it...

rezendegc avatar Apr 30 '20 14:04 rezendegc

thanks! i never thought of using while, i struggle implementing it on for loop but no luck.

glennmichaelmejias avatar Apr 30 '20 15:04 glennmichaelmejias

if you want to use for it can be done like this:

for(ContactEdge contact = body.getContactList(); contact != null; contact = contact.next()) {
  // contact logic here
}

rezendegc avatar Apr 30 '20 15:04 rezendegc

It may be a little bit more complicated to get started with ContactListeners, but they are a lot easier to use in the long run. I will write up a PR with the system I have built for simplifying this so that others can use it too.

spydon avatar Apr 30 '20 19:04 spydon

There we go. Once #304 is in, it will be a lot simpler to do this. You can have a look at it already if you want, and comment if you want it to have a different behaviour than how I suggested.

spydon avatar Apr 30 '20 23:04 spydon

#304 is on 0.20.1

erickzanardo avatar May 07 '20 13:05 erickzanardo