private Color getColorByBody (Body body) { if (body.isActive() == false) return SHAPE_NOT_ACTIVE; else if (body.getType() == BodyType.StaticBody) return SHAPE_STATIC; else if (body.getType() == BodyType.KinematicBody) return SHAPE_KINEMATIC; else if (body.isAwake() == false) return SHAPE_NOT_AWAKE; else return SHAPE_AWAKE; }
@Override public void beginContact (Contact contact) { System.out.println(String.format("beginContact() addr=%d", getContactAddr(contact))); System.out.println(String.format("beginContact() addrA=%d, addrB=%d", getFixtureAddrA(contact), getFixtureAddrB(contact))); System.out.println(String.format("beginContact() fixA=%s, fixB=%s", contact.getFixtureA(), contact.getFixtureB())); final Body toRemove = contact.getFixtureA().getBody().getType() == BodyType.DynamicBody ? contact.getFixtureA().getBody() : contact.getFixtureB().getBody(); Gdx.app.postRunnable(new Runnable() { @Override public void run () { world.destroyBody(toRemove); } }); }
@Override public void render () { if (m_platform.getType() == BodyType.KinematicBody) { Vector2 p = m_platform.getTransform().getPosition(); Vector2 v = m_platform.getLinearVelocity(); if ((p.x < -10 && v.x < 0) || (p.x > 10 && v.x > 0)) { v.x = -v.x; m_platform.setLinearVelocity(v); } } super.render(); // if (renderer.batch != null) { // renderer.batch.begin(); // // renderer.batch.drawText(renderer.font, "Keys: (d) dynamic, (s) static, (k) kinematic", 0, Gdx.app.getGraphics() // // .getHeight(), Color.WHITE); // renderer.batch.end(); // } } }
protected void renderBody (Body body) { Transform transform = body.getTransform(); int len = body.getFixtureList().size; Array<Fixture> fixtures = body.getFixtureList(); for (int i = 0; i < len; i++) { Fixture fixture = fixtures.get(i); if (drawBodies) { if (body.isActive() == false && drawInactiveBodies) drawShape(fixture, transform, SHAPE_NOT_ACTIVE); else if (body.getType() == BodyType.StaticBody) drawShape(fixture, transform, SHAPE_STATIC); else if (body.getType() == BodyType.KinematicBody) drawShape(fixture, transform, SHAPE_KINEMATIC); else if (body.isAwake() == false) drawShape(fixture, transform, SHAPE_NOT_AWAKE); else drawShape(fixture, transform, SHAPE_AWAKE); } if (drawAABBs) { drawAABB(fixture, transform); } } }
@Override public boolean touchDown (int x, int y, int pointer, int button) { // translate the mouse coordinates to world coordinates camera.unproject(testPoint.set(x, y, 0)); // ask the world which bodies are within the given // bounding box around the mouse pointer hitBody = null; world.QueryAABB(callback, testPoint.x - 0.0001f, testPoint.y - 0.0001f, testPoint.x + 0.0001f, testPoint.y + 0.0001f); if (hitBody == groundBody) hitBody = null; // ignore kinematic bodies, they don't work with the mouse joint if (hitBody != null && hitBody.getType() == BodyType.KinematicBody) return false; // if we hit something we create a new mouse joint // and attach it to the hit body. if (hitBody != null) { MouseJointDef def = new MouseJointDef(); def.bodyA = groundBody; def.bodyB = hitBody; def.collideConnected = true; def.target.set(testPoint.x, testPoint.y); def.maxForce = 1000.0f * hitBody.getMass(); mouseJoint = (MouseJoint)world.createJoint(def); hitBody.setAwake(true); } return false; }
private Color getColorByBody (Body body) { if (body.isActive() == false) return SHAPE_NOT_ACTIVE; else if (body.getType() == BodyType.StaticBody) return SHAPE_STATIC; else if (body.getType() == BodyType.KinematicBody) return SHAPE_KINEMATIC; else if (body.isAwake() == false) return SHAPE_NOT_AWAKE; else return SHAPE_AWAKE; }
@Override public boolean reportFixture(Fixture fixture) { // TODO Auto-generated method stub if(fixture.getBody().getType() != BodyType.StaticBody) { bodiesWithinArea.add(fixture.getBody()); } return true; }