コード例 #1
0
ファイル: GameScreen.java プロジェクト: Schimpa/AdventureFun
 @Override
 public void dispose() {
   worldLoader.dispose();
   debugRenderer.dispose();
   camera.dispose();
   game.dispose();
 }
コード例 #2
0
  public void render() {

    // clear screen
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // set cam to follow player
    cam.position.set(player.getPosition().x * PPM + Game.WIDTH / 4, Game.HEIGHT / 2, 0);
    cam.update();

    // draw map
    tmr.setView(cam);
    tmr.render();

    // draw player
    sb.setProjectionMatrix(cam.combined);
    player.render(sb);

    // draw coins
    for (int i = 0; i < coins.size; i++) {
      coins.get(i).render(sb);
    }

    // draw b2d world

    if (debug) b2dr.render(world, b2dcam.combined);
  }
コード例 #3
0
  public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    // tell the camera to update its matrices.
    camera.update(
        car.body.getPosition().x * PIXELS_PER_METER, car.body.getPosition().y * PIXELS_PER_METER);

    spriteBatch.setProjectionMatrix(camera.getCombined());

    if (Gdx.input.isKeyPressed(Input.Keys.UP) || Gdx.input.isTouched()) {
      car.setAccelerate(Car.ACC_ACCELERATE);
    } else if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
      car.setAccelerate(Car.ACC_BRAKE);
    } else {
      car.setAccelerate(Car.ACC_NONE);
    }

    if (Gdx.input.isKeyPressed(Input.Keys.LEFT) || Gdx.input.getAccelerometerY() < -2.5) {
      car.setSteer(Car.STEER_HARD_LEFT);
    } else if (Gdx.input.getAccelerometerY() < -1) {
      car.setSteer(Car.STEER_LEFT);
    } else if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) || Gdx.input.getAccelerometerY() > 2.5) {
      car.setSteer(Car.STEER_HARD_RIGHT);
    } else if (Gdx.input.getAccelerometerY() > 1) {
      car.setSteer(Car.STEER_RIGHT);
    } else {
      car.setSteer(Car.STEER_NONE);
    }

    car.update(Gdx.app.getGraphics().getDeltaTime());

    /**
     * Have box2d update the positions and velocities (and etc) of all tracked objects. The second
     * and third argument specify the number of iterations of velocity and position tests to perform
     * -- higher is more accurate but is also slower.
     */
    world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3);

    world.clearForces();

    // draw the sprites
    spriteBatch.begin();

    playerSprite.setPosition(
        PIXELS_PER_METER * car.body.getPosition().x - playerTexture.getRegionWidth() / 2,
        PIXELS_PER_METER * car.body.getPosition().y - playerTexture.getRegionHeight() / 2);
    playerSprite.setRotation((MathUtils.radiansToDegrees * car.body.getAngle()));

    playerSprite.setFlip(false, true);
    playerSprite.setScale(0.3f);

    playerSprite.draw(spriteBatch);

    spriteBatch.end();

    /** Draw this last, so we can see the collision boundaries on top of the sprites and map. */
    debugRenderer.render(
        world, camera.getCombined().scale(PIXELS_PER_METER, PIXELS_PER_METER, PIXELS_PER_METER));
  }
コード例 #4
0
 public void dispose() {
   renderer.dispose();
   world.dispose();
   renderer = null;
   world = null;
   hitBody = null;
 }
コード例 #5
0
ファイル: Box2DTest.java プロジェクト: WaDelma/libgdx
 @Override
 public void dispose() {
   world.dispose();
   renderer.dispose();
   debugRenderer.dispose();
   font.dispose();
   textureRegion.getTexture().dispose();
 }
コード例 #6
0
ファイル: RenderingSystem.java プロジェクト: vladsvs/sioncore
  @Override
  public void dispose() {
    if (mapRenderer != null) {
      mapRenderer.dispose();
      mapRenderer = null;
    }

    batch.dispose();
    shapeRenderer.dispose();
    box2DRenderer.dispose();
    //		particleFrameBuffer.dispose();
  }
コード例 #7
0
 private void renderWorld(SpriteBatch batch) {
   worldController.cameraHelper.applyTo(camera);
   batch.setProjectionMatrix(camera.combined);
   batch.begin();
   if (GamePreferences.instance.useMonochromeShader) {
     batch.setShader(shaderMonochrome);
     shaderMonochrome.setUniformf("u_amount", 1.0f);
   }
   worldController.level.render(batch);
   batch.setShader(null);
   batch.end();
   if (DEBUG_DRAW_BOX2D_WORLD) b2debugRenderer.render(worldController.b2world, camera.combined);
 }
コード例 #8
0
  public void render(OrthographicCamera camera) {
    // update the world with a fixed time step
    world.step(Gdx.app.getGraphics().getDeltaTime() * 10, 8, 3);
    if (mouseJoint != null) mouseJoint.setTarget(bob.getBody().getWorldCenter());

    // Destroy mouseJoint? (drop item)
    if (destroyMousejoint == true) {
      if (!world.isLocked()) {
        world.destroyJoint(mouseJoint);
        mouseJoint = null;
        destroyMousejoint = false;
      }
    }

    // Delete any bodies up for deletion
    if (!bodiesToDelete.isEmpty()) {
      // Make sure it is safe to delete!!
      if (!world.isLocked()) {
        for (Body body : bodiesToDelete) {
          world.destroyBody(body);
          body.setUserData(null);
          body = null;
        }
        bodiesToDelete.clear(); // Don't forget to clear the null bodies!
      }
    }

    // Create any bodies up for creation
    if (!bodiesToCreate.isEmpty()) {
      // Make sure it is safe to create!!
      if (!world.isLocked()) {
        for (BodyDef body : bodiesToCreate) {
          world.createBody(body);
        }
        bodiesToCreate.clear(); // Don't forget to clear!
      }
    }

    // Create any joints up for creation
    if (!jointsToCreate.isEmpty()) {
      // Make sure it is safe to create!!
      if (!world.isLocked()) {
        for (JointDef body : jointsToCreate) {
          mouseJoint = (MouseJoint) world.createJoint(body);
        }
        jointsToCreate.clear(); // Don't forget to clear!
      }
    }
    // render the world using the debug renderer
    renderer.render(world, camera.combined);
  }
コード例 #9
0
ファイル: MyGame.java プロジェクト: LeereMenge/box2d_example
  @Override
  public void render() {

    if (platform.getPosition().x > 10) {
      platform.setLinearVelocity(-PLATFORM_VELOCITY, 0);
    } else if (platform.getPosition().x < -10) {
      platform.setLinearVelocity(PLATFORM_VELOCITY, 0);
    }

    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    world.step(1 / 60f, 6, 2);
    dDebugRenderer.render(world, cam.combined);
  }
コード例 #10
0
ファイル: Main.java プロジェクト: MurderousFrog/NikosWorld
  @Override
  public void render() {
    update(Gdx.graphics.getDeltaTime());

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    batch.begin();
    batch.draw(
        texture,
        player.getPosition().x * PPM - (texture.getWidth() / 2),
        player.getPosition().y * PPM - (texture.getHeight() / 2));
    batch.end();

    b2dr.render(world, camera.combined.scl(PPM));

    if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) Gdx.app.exit();
  }
コード例 #11
0
  @Override
  public void render() {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    float delta = Gdx.graphics.getDeltaTime();

    if (delta > MAX_DELTA_TIME) {
      delta = MAX_DELTA_TIME;
    }

    mAccumulator += delta;

    while (mAccumulator >= mSecondsPerStep) {
      mWorld.step(mSecondsPerStep, mVelocityIter, mPositionIter);
      mAccumulator -= mSecondsPerStep;
    }

    if ((spatials != null) && (spatials.size > 0)) {
      batch.setProjectionMatrix(camera.combined);
      batch.begin();
      for (int i = 0; i < spatials.size; i++) {
        spatials.get(i).render(batch, 0);
      }
      batch.end();
    }

    if ((polySpatials != null) && (polySpatials.size > 0)) {
      polygonBatch.setProjectionMatrix(camera.combined);
      polygonBatch.begin();
      for (int i = 0; i < polySpatials.size; i++) {
        polySpatials.get(i).render(polygonBatch, 0);
      }
      polygonBatch.end();
    }

    batch.setProjectionMatrix(textCam.combined);
    batch.begin();
    bitmapFont.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
    batch.end();

    debugRender.render(mWorld, camera.combined);
  }
コード例 #12
0
  @Override
  public void render(SpriteBatch spriteBatch) {
    // clear screen
    Gdx.gl.glClear(Gdx.gl.GL_COLOR_BUFFER_BIT);
    Texture texture = FileManager.getManager().getTexture(null, "background");
    spriteBatch.begin();

    // Background
    spriteBatch.draw(texture, startScreenX(), startScreenY(), getScreenWidth(), getScreenHeight());

    renderBalls(spriteBatch);
    renderPlayerInfo(spriteBatch);

    // player
    player = Player.getPlayer();
    TextureRegion textureRegion = player.anim.getKeyFrame(passedTime, true);
    TextureRegion textureRegion1 = Weapon.getWeapon().anim.getKeyFrame(passedTime, true);
    weapon = Weapon.getWeapon();

    spriteBatch.draw(
        textureRegion,
        player.playerBody.getPosition().x - player.width / 2,
        player.playerBody.getPosition().y - player.height / 2,
        player.width,
        player.height);

    // Weapon draw while actived by touch
    if (Weapon.getWeapon().isActive) {
      spriteBatch.draw(
          textureRegion1,
          weapon.weaponBody.getPosition().x - weapon.width / 2,
          weapon.weaponBody.getPosition().y - weapon.height / 2,
          weapon.width,
          weapon.height);
    } else {
      if (Weapon.getWeapon().weaponBody != null) Weapon.getWeapon().weaponBody.setActive(false);
    }
    spriteBatch.end();
    // draw box2d world
    box2DDebugRenderer.render(world, orthoCam.combined);
  }
コード例 #13
0
  @Override
  public void render() {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.position.set(circleBody.getPosition().x, circleBody.getPosition().y, 0);
    camera.update();
    renderer.render(world, camera.combined);
    System.out.println(
        "player.getPosition().x = "
            + player.getPosition().x
            + "\nplayer.getPosition().y = "
            + player.getPosition().y
            + "\ncamera.position = "
            + camera.position);
    Sprite sprite;
    sprite = (Sprite) circleBody.getUserData();
    // set position and width and height and makes sure it is in the center
    sprite.setBounds(
        convertToWorld(circleBody.getPosition().x) - sprite.getWidth() / 2,
        convertToWorld(circleBody.getPosition().y) - sprite.getHeight() / 2,
        convertToWorld(circleShape.getRadius() * 2),
        convertToWorld(circleShape.getRadius() * 2));

    tiledMapRenderer.setView(camera);
    tiledMapRenderer.render();

    System.out.println(
        "Bouncing circle: " + circleBody.getMass() + "\n" + "Player: " + player.getMass());

    // world.step(1/45f, 6, 2);
    world.step(Gdx.graphics.getDeltaTime(), 4, 4);
    player.setAwake(true);
    // camera.project(point.set(player.getPosition().x, player.getPosition().y, 0));

    // logger.log();
    batch.begin();
    // Circle.draw(batch);
    sprite.draw(batch);
    batch.end();
  }
コード例 #14
0
  @Override
  public void update(float deltaTime) {
    super.update(deltaTime);
    debugRenderer.render(world, camera.combined);
    float frameTime = Math.min(deltaTime, 0.25f);
    accumulator += frameTime;
    if (accumulator >= MAX_STEP_TIME) {
      world.step(MAX_STEP_TIME, 6, 2);
      accumulator -= MAX_STEP_TIME;

      // Entity Queue
      for (Entity entity : bodiesQueue) {
        TransformComponent t = tm.get(entity);
        BodyComponent body = bm.get(entity);
        Vector2 pos = body.body.getPosition();
        pos.x = t.pos.x;
        pos.y = t.pos.y;
        body.body.setTransform(pos, t.rotation * MathUtils.degreesToRadians);
      }
    }
    bodiesQueue.clear();
  }
コード例 #15
0
ファイル: FiubaGame.java プロジェクト: astamato/ninja-rabbit
  @Override
  public void render() {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.graphics.setTitle(String.format(GAME_TITLE, Gdx.graphics.getFramesPerSecond()));
    world.step(TIME_STEP, 8, 3);

    viewport.getCamera().position.x =
        ninjaRabbit.getBody() == null
            ? 0.0f
            : ninjaRabbit.getBody().getPosition().x + viewport.getWorldWidth() / 4.0f;
    viewport.getCamera().update();
    batch.setProjectionMatrix(viewport.getCamera().combined);

    tileMapRenderer.setView((OrthographicCamera) viewport.getCamera());
    tileMapRenderer.render();

    batch.begin();
    ninjaRabbit.update(batch);
    batch.end();

    b2dRenderer.render(world, viewport.getCamera().combined);
  }
コード例 #16
0
ファイル: _3TestMovement.java プロジェクト: jmmosa/otakurun
  @Override
  public void render() {
    long now = System.nanoTime();
    update();
    clearScreen();

    //		tiledMapHelper.getCamera().position.x = PIXELS_PER_METER * tokine.body.getPosition().x;
    camera.position.x = Constants.PIXELS_PER_METER * tokine.body.getPosition().x;

    handleScreenBoundaries();

    tiledMapHelper.getCamera().update();
    tiledMapHelper.render();

    batch.begin();
    tokine.render(batch, camera);
    batch.end();

    /** Draw this last, so we can see the collision boundaries on top of the sprites and map. */
    camera.update();
    debugRenderer.render(
        world,
        tiledMapHelper
            .getCamera()
            .combined
            .scale(
                Constants.PIXELS_PER_METER,
                Constants.PIXELS_PER_METER,
                Constants.PIXELS_PER_METER));

    if (now - lastRender < 30000000) { // 30 ms, ~33FPS
      try {
        Thread.sleep(30 - (now - lastRender) / 1000000);
      } catch (InterruptedException e) {
      }
    }
    lastRender = now;
  }
コード例 #17
0
ファイル: RenderingSystem.java プロジェクト: vladsvs/sioncore
  protected void debugDrawWorld() {
    if (Env.debug) {

      shapeRenderer.setProjectionMatrix(camera.combined);

      if (Env.drawGrid) {
        // Debug shapes
        shapeRenderer.setColor(1.0f, 0.0f, 0.0f, 1.0f);
        shapeRenderer.begin(ShapeType.Line);
        shapeRenderer.line(-Env.virtualWidth * 0.5f, 0.0f, Env.virtualWidth * 0.5f, 0.0f);
        shapeRenderer.line(0.0f, -Env.virtualHeight * 0.5f, 0.0f, Env.virtualHeight * 0.5f);

        shapeRenderer.setColor(0.0f, 1.0f, 0.0f, 1.0f);

        for (int i = -100; i <= 100; ++i) {
          if (i == 0) continue;

          shapeRenderer.line(-Env.virtualWidth * 0.5f, i, Env.virtualWidth * 0.5f, i);
        }

        for (int i = -100; i <= 100; ++i) {
          if (i == 0) continue;

          shapeRenderer.line(i, -Env.virtualHeight * 0.5f, i, Env.virtualHeight * 0.5f);
        }

        shapeRenderer.end();
      }

      box2DRenderer.setDrawAABBs(Env.drawABBs);
      box2DRenderer.setDrawBodies(Env.drawBodies);
      box2DRenderer.setDrawContacts(Env.drawContacts);
      box2DRenderer.setDrawInactiveBodies(Env.drawInactiveBodies);
      box2DRenderer.setDrawJoints(Env.drawJoints);
      box2DRenderer.setDrawVelocities(Env.drawVelocities);
      box2DRenderer.render(Env.game.getWorld(), camera.combined);
    }
  }
コード例 #18
0
ファイル: Main.java プロジェクト: MurderousFrog/NikosWorld
 @Override
 public void dispose() {
   world.dispose();
   b2dr.dispose();
   batch.dispose();
 }
コード例 #19
0
ファイル: Box2DTest.java プロジェクト: WaDelma/libgdx
  @Override
  public void render() {
    // first we update the world. For simplicity
    // we use the delta time provided by the Graphics
    // instance. Normally you'll want to fix the time
    // step.
    long start = TimeUtils.nanoTime();
    world.step(Gdx.graphics.getDeltaTime(), 8, 3);
    float updateTime = (TimeUtils.nanoTime() - start) / 1000000000.0f;

    // next we clear the color buffer and set the camera
    // matrices
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();

    // next we render the ground body
    renderBox(groundBody, 50, 1);

    // next we render each box via the SpriteBatch.
    // for this we have to set the projection matrix of the
    // spritebatch to the camera's combined matrix. This will
    // make the spritebatch work in world coordinates
    batch.getProjectionMatrix().set(camera.combined);
    batch.begin();
    for (int i = 0; i < boxes.size(); i++) {
      Body box = boxes.get(i);
      Vector2 position = box.getPosition(); // that's the box's center position
      float angle =
          MathUtils.radiansToDegrees * box.getAngle(); // the rotation angle around the center
      batch.draw(
          textureRegion,
          position.x - 1,
          position.y - 1, // the bottom left corner of the box, unrotated
          1f,
          1f, // the rotation center relative to the bottom left corner of the box
          2,
          2, // the width and height of the box
          1,
          1, // the scale on the x- and y-axis
          angle); // the rotation angle
    }
    batch.end();

    // next we use the debug renderer. Note that we
    // simply apply the camera again and then call
    // the renderer. the camera.apply() call is actually
    // not needed as the opengl matrices are already set
    // by the spritebatch which in turn uses the camera matrices :)
    debugRenderer.render(world, camera.combined);

    // finally we render all contact points
    renderer.setProjectionMatrix(camera.combined);
    renderer.begin(ShapeType.Point);
    renderer.setColor(0, 1, 0, 1);
    for (int i = 0; i < world.getContactCount(); i++) {
      Contact contact = world.getContactList().get(i);
      // we only render the contact if it actually touches
      if (contact.isTouching()) {
        // get the world manifold from which we get the
        // contact points. A manifold can have 0, 1 or 2
        // contact points.
        WorldManifold manifold = contact.getWorldManifold();
        int numContactPoints = manifold.getNumberOfContactPoints();
        for (int j = 0; j < numContactPoints; j++) {
          Vector2 point = manifold.getPoints()[j];
          renderer.point(point.x, point.y, 0);
        }
      }
    }
    renderer.end();

    // finally we render the time it took to update the world
    // for this we have to set the projection matrix again, so
    // we work in pixel coordinates
    batch
        .getProjectionMatrix()
        .setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.begin();
    font.draw(
        batch, "fps: " + Gdx.graphics.getFramesPerSecond() + " update time: " + updateTime, 0, 20);
    batch.end();
  }
コード例 #20
0
ファイル: AIWorld.java プロジェクト: narfman0/badge
 public void render(Box2DDebugRenderer renderer, Matrix4 proj) {
   if (nodesVisible || edgesVisible) renderer.render(world, proj);
 }
コード例 #21
0
ファイル: PhysicsWorld.java プロジェクト: Juginabi/ProjectGDX
 public void render(OrthographicCamera camera) {
   if (debugRenderingEnabled_) {
     debugRenderer_.render(world_, camera.combined);
   }
 }
コード例 #22
0
ファイル: Game.java プロジェクト: darthdeus/shipr
  @Override
  public void render() {
    Gdx.gl.glClearColor(0.1f, 0.1f, 0.2f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    world.step(1 / 60f, 6, 2);

    camera.position.set(ship.getPosition().x, ship.getPosition().y, 0);

    ship.fixture.getBody().setAngularVelocity(0);

    Vector2 direction = null;

    if (Gdx.input.isKeyJustPressed(Input.Keys.Q) || Gdx.input.isTouched()) {
      ship.shoot();
      ship.mouseMoved(camera, Gdx.input.getX(), WINDOW_HEIGHT - Gdx.input.getY());
    }
    if (Gdx.input.isKeyPressed(Input.Keys.A)) {
      direction = new Vector2(-1, 0);
      ship.applyForce(direction);
    }
    if (Gdx.input.isKeyPressed(Input.Keys.D)) {
      direction = new Vector2(1, 0);
      ship.applyForce(direction);
    }
    if (Gdx.input.isKeyPressed(Input.Keys.S)) {
      direction = new Vector2(0, -1);
      ship.applyForce(direction);
    }
    if (Gdx.input.isKeyPressed(Input.Keys.W)) {
      direction = new Vector2(0, 1);
      ship.applyForce(direction);
    }
    if (Gdx.input.isKeyPressed(Input.Keys.SPACE)) {
      ship.stop();
    }

    if (Gdx.input.isKeyJustPressed(Input.Keys.N)) {
      Random random = new Random();
      float size = random.nextFloat() * 30 + 20;
      float x = random.nextFloat() * (WINDOW_WIDTH / 2 - size);
      float y = random.nextFloat() * (WINDOW_HEIGHT / 2 - size);

      System.out.printf("Spawned %f at %f %f\n", size, x, y);

      final Asteroid asteroid = Asteroid.createIn(world, size, x, y);

      asteroids.add(asteroid);
    }

    camera.update();
    batch.setProjectionMatrix(camera.combined);

    batch.begin();
    ship.draw(batch);

    for (Asteroid asteroid : asteroids) {
      asteroid.draw(batch);
    }

    BitmapFont font = new BitmapFont();
    Body body = ship.fixture.getBody();
    Vector2 velocity = body.getLinearVelocity();

    batch.end();

    hudBatch.begin();

    String state =
        String.format(
            "Velocity: %f %f\nPosition: %f %f\nZoom: %f",
            velocity.x, velocity.y, body.getPosition().x, body.getPosition().y, camera.zoom);

    font.draw(hudBatch, state, 50, 50);

    hudBatch.end();

    box2dRenderer.render(world, camera.combined);
  }
コード例 #23
0
ファイル: FiubaGame.java プロジェクト: astamato/ninja-rabbit
 @Override
 public void dispose() {
   ninjaRabbit.dispose();
   b2dRenderer.dispose();
   world.dispose();
 }