public void initWorld() { Vec2 gravity = new Vec2(0.0f, 9.8f); world = new World(gravity); // ground FixtureDef groundFixtureDef = new FixtureDef(); PolygonShape groundShape = new PolygonShape(); groundShape.setAsBox(20f, 0.1f); groundFixtureDef.shape = groundShape; groundFixtureDef.density = 25.0f; groundFixtureDef.filter = new Filter(); groundFixtureDef.filter.categoryBits = 0x0001; BodyDef groundBodyDef = new BodyDef(); groundBodyDef.position = new Vec2(0.0f, 3f); groundBodyDef.angle = 0.0f; groundBodyDef.type = BodyType.STATIC; groundBody = world.createBody(groundBodyDef); groundFixture = groundBody.createFixture(groundFixtureDef); }
private Entity buildFloorEntity(World world) { Entity e = engine.createEntity(); Vector2 screenMeters = RenderingSystem.getScreenSizeInMeters(); Gdx.app.log("Splash Screen", "Screen Meters:" + screenMeters.x + " x " + screenMeters.y); Vector2 screenPixels = RenderingSystem.getScreenSizeInPixesl(); Gdx.app.log("Splash Screen", "Screen Pixels:" + screenPixels.x + " x " + screenPixels.y); // Create our body definition BodyDef groundBodyDef = new BodyDef(); groundBodyDef.type = BodyDef.BodyType.StaticBody; // Set its world position groundBodyDef.position.set(new Vector2(6f, 1f)); groundBodyDef.angle = 45f; BodyComponent bc = new BodyComponent(); // Create a body from the defintion and add it to the world bc.body = world.createBody(groundBodyDef); // Create a polygon shape PolygonShape groundBox = new PolygonShape(); // Set the polygon shape as a box which is twice the size of our view port and 20 high // (setAsBox takes half-width and half-height as arguments) groundBox.setAsBox(5f, 1f); // Create a fixture from our polygon shape and add it to our ground body bc.body.createFixture(groundBox, 0.0f); // Clean up after ourselves groundBox.dispose(); e.add(bc); return e; }