コード例 #1
0
  private void init() {
    Gdx.app.log("GameScreen", "Initializing");
    isInitialized = true;

    world = new World(new Vector2(0f, -9.8f), true);
    // Add Texture Component
    engine = new PooledEngine();

    RenderingSystem renderingSystem = new RenderingSystem(batch);
    engine.addSystem(new AnimationSystem());
    engine.addSystem(renderingSystem);
    engine.addSystem(new PhysicsSystem(world));

    engine.addSystem(new PhysicsDebugSystem(world, renderingSystem.getCamera()));
    engine.addSystem(new UselessStateSwapSystem());

    Entity e = buildPuffin(world);
    engine.addEntity(e);
    engine.addEntity(buildFloorEntity(world));

    isInitialized = true;
  }
コード例 #2
0
  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;
  }