/** * Removes all physics controls and joints in the given spatial from the physics space (e.g. * before saving to disk) - recursive if node * * @param spatial the rootnode containing the physics objects */ public void removeAll(Spatial spatial) { if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); // remove joints with physicsNode as BodyA List<PhysicsJoint> joints = physicsNode.getJoints(); for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext(); ) { PhysicsJoint physicsJoint = it1.next(); if (physicsNode.equals(physicsJoint.getBodyA())) { removeJoint(physicsJoint); // remove(physicsJoint.getBodyB()); } } remove(physicsNode); } else if (spatial.getControl(PhysicsControl.class) != null) { remove(spatial); } // recursion if (spatial instanceof Node) { List<Spatial> children = ((Node) spatial).getChildren(); for (Iterator<Spatial> it = children.iterator(); it.hasNext(); ) { Spatial spat = it.next(); removeAll(spat); } } }
public void nextCar() { if (index == 3) { index = 0; localRootNode.detachChild(cars[3]); space.remove(car_con[3]); localRootNode.attachChild(cars[index]); space.add(car_con[index]); } else if (index != 3) { localRootNode.detachChild(cars[index]); space.remove(car_con[index]); ++index; localRootNode.attachChild(cars[index]); space.add(car_con[index]); } }
protected void removeFromPhysicsSpace() { if (space == null) { return; } if (baseRigidBody != null) { space.remove(baseRigidBody); } for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext(); ) { PhysicsBoneLink physicsBoneLink = it.next(); if (physicsBoneLink.joint != null) { space.remove(physicsBoneLink.joint); if (physicsBoneLink.rigidBody != null) { space.remove(physicsBoneLink.rigidBody); } } } added = false; }
public void startGame() { space.remove(car_con[index]); localRootNode.detachChild(cars[index]); localRootNode.detachChild(floor); carView.detachScene(localRootNode); stateManager.detach(this); gameState.setName(playerName); gameState.setCar(car_names[index]); gameState.setLevel(1, false); gameState.setDefeatedCars(0); stateManager.attach(gameState); }
public void nextScreen(String name) { if (name.equals("controls")) { nifty.gotoScreen(name); } if (name.equals("name")) { nifty.gotoScreen(name); } if (name.equals("start")) { nifty.gotoScreen(name); space.remove(car_con[index]); localRootNode.detachChild(cars[index]); localRootNode.removeLight(ai); localRootNode.removeLight(dl); localRootNode.detachChild(floor); } if (name.equals("settings")) { nifty.gotoScreen(name); } if (name.equals("credits")) { nifty.gotoScreen(name); } if (name.equals("startMenu")) { nifty.gotoScreen("start"); } if (name.equals("carSelect")) { playerName = textfield.getText(); if (!"".equals(playerName)) { nifty.gotoScreen(name); showCar(); } } if (name.equals("startSettings")) { int res = settingsList.getFocusItemIndex(); boolean fullScreen = true; boolean vSync = true; AppSettings settings = new AppSettings(true); settings.setFullscreen(fullScreen); settings.setVSync(vSync); settings.setResolution(width[res], height[res]); app.setSettings(settings); nifty.gotoScreen("start"); } }
/** * removes an object from the physics space * * @param obj the PhysicsControl or Spatial with PhysicsControl to remove */ public void remove(Object obj) { if (obj == null) return; if (obj instanceof PhysicsControl) { ((PhysicsControl) obj).setPhysicsSpace(null); } else if (obj instanceof Spatial) { Spatial node = (Spatial) obj; for (int i = 0; i < node.getNumControls(); i++) { if (node.getControl(i) instanceof PhysicsControl) { remove(((PhysicsControl) node.getControl(i))); } } } else if (obj instanceof PhysicsCollisionObject) { removeCollisionObject((PhysicsCollisionObject) obj); } else if (obj instanceof PhysicsJoint) { removeJoint((PhysicsJoint) obj); } else { throw (new UnsupportedOperationException( "Cannot remove this kind of object from the physics space.")); } }