示例#1
0
 @Override
 public boolean touchDragged(int x, int y, int pointer) {
   // if a mouse joint exists we simply update
   // the target of the joint based on the new
   // mouse coordinates
   if (mouseJoint != null) {
     camera.unproject(testPoint.set(x, y, 0));
     mouseJoint.setTarget(target.set(testPoint.x, testPoint.y));
   }
   return false;
 }
示例#2
0
  public void render(OrthographicCamera camera) {
    // update the world with a fixed time step
    world.step(Gdx.app.getGraphics().getDeltaTime() * 10, 8, 3);
    if (mouseJoint != null) mouseJoint.setTarget(bob.getBody().getWorldCenter());

    // Destroy mouseJoint? (drop item)
    if (destroyMousejoint == true) {
      if (!world.isLocked()) {
        world.destroyJoint(mouseJoint);
        mouseJoint = null;
        destroyMousejoint = false;
      }
    }

    // Delete any bodies up for deletion
    if (!bodiesToDelete.isEmpty()) {
      // Make sure it is safe to delete!!
      if (!world.isLocked()) {
        for (Body body : bodiesToDelete) {
          world.destroyBody(body);
          body.setUserData(null);
          body = null;
        }
        bodiesToDelete.clear(); // Don't forget to clear the null bodies!
      }
    }

    // Create any bodies up for creation
    if (!bodiesToCreate.isEmpty()) {
      // Make sure it is safe to create!!
      if (!world.isLocked()) {
        for (BodyDef body : bodiesToCreate) {
          world.createBody(body);
        }
        bodiesToCreate.clear(); // Don't forget to clear!
      }
    }

    // Create any joints up for creation
    if (!jointsToCreate.isEmpty()) {
      // Make sure it is safe to create!!
      if (!world.isLocked()) {
        for (JointDef body : jointsToCreate) {
          mouseJoint = (MouseJoint) world.createJoint(body);
        }
        jointsToCreate.clear(); // Don't forget to clear!
      }
    }
    // render the world using the debug renderer
    renderer.render(world, camera.combined);
  }