private Entity buildPuffin(World world) { Entity e = engine.createEntity(); e.add(new PuffinComponent()); AnimationComponent a = new AnimationComponent(); a.animations.put( "DEFAULT", new Animation(1f / 16f, Assets.getPuffinArray(), Animation.PlayMode.LOOP)); a.animations.put( "RUNNING", new Animation(1f / 16f, Assets.getPuffinRunArray(), Animation.PlayMode.LOOP)); e.add(a); StateComponent state = new StateComponent(); state.set("DEFAULT"); e.add(state); TextureComponent tc = new TextureComponent(); e.add(tc); TransformComponent tfc = new TransformComponent(); tfc.position.set(10f, 10f, 1f); tfc.rotation = 15f; tfc.scale.set(0.25f, 0.25f); e.add(tfc); BodyComponent bc = new BodyComponent(); BodyDef bodyDef = new BodyDef(); // We set our body to dynamic, for something like ground which doesn't move we would set it to // StaticBody bodyDef.type = BodyDef.BodyType.DynamicBody; // Set our body's starting position in the world bodyDef.position.set(10f, 23f); // Create our body in the world using our body definition bc.body = world.createBody(bodyDef); bc.body.applyAngularImpulse(50f, true); // Create a circle shape and set its radius to 6 CircleShape circle = new CircleShape(); circle.setRadius(2f); // Create a fixture definition to apply our shape to FixtureDef fixtureDef = new FixtureDef(); fixtureDef.shape = circle; fixtureDef.density = 20f; fixtureDef.friction = 0.4f; fixtureDef.restitution = 0.6f; // Make it bounce a little bit // Create our fixture and attach it to the body bc.body.createFixture(fixtureDef); // Remember to dispose of any shapes after you're done with them! // BodyDef and FixtureDef don't need disposing, but shapes do. circle.dispose(); e.add(bc); return e; }
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; }