Skip to content

Instantly share code, notes, and snippets.

@Tom-Ski
Created February 15, 2014 01:37
Show Gist options
  • Save Tom-Ski/9013168 to your computer and use it in GitHub Desktop.
Save Tom-Ski/9013168 to your computer and use it in GitHub Desktop.
maximtwo is my hero
protected void loadFixtures(TiledMap map, World world) {
MapLayer fixturesLayer = map.getLayers().get("fixtures");
Array<PolylineMapObject> fixtures = fixturesLayer.getObjects().getByType(PolylineMapObject.class);
BodyDef bd = new BodyDef();
bd.type = BodyType.StaticBody;
groundBody = world.createBody(bd);
groundBody.setUserData(-1);
FixtureDef fd = new FixtureDef();
fd.density = 1.0f;
fd.friction = 0.3f;
fd.filter.categoryBits = ContactFilters.BOUNDARY;
fd.filter.maskBits = (short) (ContactFilters.PLAYER | ContactFilters.POTATO | ContactFilters.CRATE);
for(int i = 0; i < fixtures.size; ++i) {
ChainShape cs = new ChainShape();
fd.shape = cs;
Polyline fixture = fixtures.get(i).getPolyline();
float[] vertices = fixture.getTransformedVertices();
for(int j = 0; j < vertices.length; ++j) {
vertices[j] /= PIXELS_PER_METER;
}
cs.createChain(vertices);
groundBody.createFixture(fd);
cs.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment