public void update() { Iterable<StableContact> contacts = Game.get().getLevel().getContactHandler() .getContacts(this); // get the bodies touching this actor Iterable<Body> bodies = ContactHandler.getBodies(contacts); Actor actor; for (Body b : bodies) { // only concerned with dynamic bodies (we don't want to respond // background bodies) if (b.getType() != BodyType.DynamicBody || ((Actor)b.getUserData()) instanceof JiggleBall) continue; actor = (Actor) b.getUserData(); // skip the blob body if respawner ignores blobs if (Convert.getInt(getProp("Ignore Blobs")) == 1 && actor instanceof Blob) continue; // skip non-blob body if respawner ignores non-blobs if (Convert.getInt(getProp("Ignore Non-Blobs")) == 1 && !(actor instanceof Blob)) continue; if (actor instanceof Blob){ ((Blob)actor).mExtraGlow = -100; } int targetId = Convert.getInt(getProp("Target Spawner")); // there is a targeted spawner to send actors to if (targetId != -1) { Spawner sp = (Spawner) mLevel.getActorById(targetId); sp.addToSpawn(actor, Convert.getInt(getProp("Delay"))); Array<JointEdge> edges = b.getJointList(); for (int i = 0; i < edges.size; i++) { JointEdge edge = edges.get(i); // get the other actor this joint is connected to // if the other actor is not itself and is a blob Actor otherActor = (Actor) edge.other.getUserData(); if (otherActor != actor && (otherActor instanceof Blob)) { // you need to watch house of cards Joint congressmanRusso = edge.joint; ((Blob) otherActor).removeJoint(congressmanRusso); if (actor instanceof Blob) { ((Blob) actor).removeJoint(congressmanRusso); } Game.get().getLevel().getWorld().destroyJoint(congressmanRusso); } } Game.get().getLevel().getContactHandler().destroyContacts(b); } } }
/** * Destruye los cuerpos de las piezas de la escena que estén marcados inactivos * ( no siendo simulados). * * Este método se ha de ejecutar en un {@link IUpdateHandler}. * NO , repito , NO es posible ejecutarse dentro de un Runnable en el * hilo de actualización sin causar problemas de sincronización en la extensión box2d * y errores en la librería nativa * */ private void purgarPiezas(){ for(ListIterator<IPieza> pi = piezasEscena.listIterator(); pi.hasNext();){ IPieza p = pi.next(); if(p.isDestruida() ){ for(JointEdge je : p.getCuerpo().getJointList()){ for(int i =0;i<joints.length;i++){ if( joints[i] == je.joint ) joints[i]=null; } } mundo.destroyBody(p.getCuerpo()); pi.remove(); } } }