@Override
  public void initialize() {
    super.initialize();

    // doStep true = not simulate inactive bodies
    world = new World(new Vector2(0.0f, 10.0f), true);
    world.setContinuousPhysics(true);
    world.setWarmStarting(true);
    world.setAutoClearForces(true);
    ValueMap valueMap = game.getGameState();
    valueMap.setValue((String) null, VAR_PH_WORLD, world);

    velocityIterations = 24;
    positionIterations = 8;

    for (SceneElement e : effect.getElements()) {
      createBody(world, e, valueMap);
    }

    for (SceneElement e : effect.getJoints()) {
      createBody(world, e, valueMap);
    }

    RevoluteJointDef jd = new RevoluteJointDef();
    jd.collideConnected = false;

    for (int i = 0; i < effect.getJoints().size() - 1; i += 2) {
      SceneElement e1 = effect.getJoints().get(i);
      SceneElement e2 = effect.getJoints().get(i + 1);
      Body b1 = (Body) valueMap.getValue(e1.getId(), VAR_PH_BODY, null);
      Body b2 = (Body) valueMap.getValue(e2.getId(), VAR_PH_BODY, null);
      jd.initialize(b2, b1, new Vector2(b1.getPosition().x, b1.getPosition().y));
      world.createJoint(jd);
    }
  }
Example #2
0
 @Override
 public void initialize() {
   super.initialize();
   time = element.getTime();
 }