Example #1
0
  public void parent(GameObject p, boolean compound) {
    CompoundShape compShapeOld = null;

    if (parent != null) {
      parent.children.remove(this);

      if (compound) {
        compShapeOld = parent.compoundShape();
        if (compShapeOld != null) {
          scene.world.removeRigidBody(parent.body);
          compShapeOld.removeChildShape(body.getCollisionShape());
          scene.world.addRigidBody(parent.body);
        }
      }

    } else if (p == null) {
      return;
    }

    parent = p;

    if (parent != null) {

      parent.children.add(this);

      updateLocalTransform();
      updateLocalScale();

      if (compound) {
        CompoundShape compShape = parent.compoundShape();
        if (compShape != null) {
          scene.world.removeRigidBody(body);
          compShape.addChildShape(new Transform(localTransform), body.getCollisionShape());
        }
      } else {
        dynamics(false);
      }

    } else if (currBodyType.equals("STATIC") || currBodyType.equals("SENSOR")) {
      if (compound && compShapeOld != null) scene.world.addRigidBody(body);

    } else {
      dynamics(true);
    }
  }