/** Get the list of all joints attached to this body. Do not modify the list! */ public Array<JointEdge> getJointList () { // FIXME wow this is bad... org.jbox2d.dynamics.joints.JointEdge jointEdge = body.getJointList(); joints.clear(); while (jointEdge != null) { JointEdge edge = new JointEdge(world.bodies.get(jointEdge.other), world.joints.get(jointEdge.joint)); joints.add(edge); jointEdge = jointEdge.next; } return joints; }
/** Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during * callbacks. * @warning This automatically deletes all associated shapes and joints. * @warning This function is locked during callbacks. */ public void destroyBody (Body body) { JointEdge jointEdge = body.body.getJointList(); while (jointEdge != null) { JointEdge next = jointEdge.next; world.destroyJoint(jointEdge.joint); joints.remove(jointEdge.joint); jointEdge = next; } world.destroyBody(body.body); bodies.remove(body.body); for (Fixture fixture : body.fixtures) { fixtures.remove(fixture.fixture); } }
CopyOnWriteArrayList<Entity> entities = new CopyOnWriteArrayList<Entity>(); public void deleteEntities() { for(Entity entity: entities){ Body body = entity.getBody(); if (body != null) { EntityData data = (EntityData) body.getUserData(); if (data.isFlaggedForDelete()) { final Array<JointEdge> list = body.getJointList(); //delete all joints attached while (list.size > 0) { myWorld.getWorld().destroyJoint(list.get(0).joint); } //nullify everything, remove the entity from entities and destroy the body body.setUserData(null); myWorld.getWorld().destroyBody(body); entities.remove(entity); body = null; } } } }