示例#1
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);
  }
 public void renderLevel() {
   if (loaded) {
     // System.out.println("renderLevel");
     levelRenderer.setView(parentCamera);
     levelRenderer.render();
   }
 }
示例#3
0
  protected void renderMap() {
    // If there are no map entities, dispose the renderer
    if (mapEntities.size == 0) {
      if (mapRenderer != null) {
        mapRenderer.dispose();
        mapRenderer = null;
      }
    } else {
      Entity mapEntity = mapEntities.values().next();
      MapComponent mapComponent = mapEntity.getComponent(MapComponent.class);

      if (map != mapComponent.map) {
        if (mapRenderer != null) {
          mapRenderer.dispose();
        }

        map = mapComponent.map;
        mapRenderer = new OrthogonalTiledMapRenderer(map, Env.pixelsToMetres);
      }

      // Render
      mapRenderer.setView(camera);
      mapRenderer.render();
    }
  }
 /**
  * Renders the tiled map for the current frame. Sets its view as the given {@link
  * OrthographicCamera}.
  *
  * @param camera The camera used to show the map.
  */
 public void render(final OrthographicCamera camera) {
   float width = 1.12f * camera.viewportWidth * camera.zoom;
   float height = camera.viewportHeight * camera.zoom;
   renderer.setView(
       camera.combined,
       camera.position.x - width / 2,
       camera.position.y - height / 2,
       width,
       height);
   renderer.render();
 }
示例#5
0
  private void renderWorld() {
    clearScreen();
    sr.setProjectionMatrix(camera.combined);

    mapRenderer.setView(camera);
    mapRenderer.render();

    sr.begin(ShapeType.Filled);
    renderNeighbourCollisionAreas(sr);
    renderPlayer(sr);
    sr.end();
  }
示例#6
0
 public void render(GameCamera gameCamera) {
   renderer.setView(gameCamera);
   renderer.render();
 }
示例#7
0
  @Override
  public void preUIrender(float delta) {
    // Game-Labels updaten
    timeLabel.setText("TIME: " + String.valueOf((System.currentTimeMillis() - startTime) / 1000));
    timeLabel.setPosition(0, uiStage.getHeight() - timeLabel.getPrefHeight() / 2);

    livesLabel.setText("LIVES: " + String.valueOf(player.getLives()));
    livesLabel.setPosition(
        (uiStage.getWidth() / 2) - (livesLabel.getPrefWidth() / 2),
        uiStage.getHeight() - timeLabel.getPrefHeight() / 2);

    // Kamera auf Spieler-X ausrichten, auf Map setzen und Map rendern
    float playerCenterPos = player.getX() + player.getEntityWidth() / 2;
    boolean playerOutLeft = playerCenterPos < (SCREEN_WIDTH / 2);
    boolean playerOutRight =
        playerCenterPos > (getMap().getMapWidthAsScreenUnits() - (SCREEN_WIDTH / 2));

    if (!playerOutLeft && !playerOutRight)
      camera.position.x = player.getX() + player.getEntityWidth() / 2;
    else {
      if (playerOutLeft) camera.position.x = SCREEN_WIDTH / 2;
      else camera.position.x = getMap().getMapWidthAsScreenUnits() - (SCREEN_WIDTH / 2);
    }
    camera.update();

    OrthogonalTiledMapRenderer renderer = map.getRenderer();
    renderer.setView(camera);
    renderer.render();

    renderer.getSpriteBatch().begin();

    // Spieler rendern
    player.render(renderer.getSpriteBatch());

    for (AbstractEntity enemy : entityList) {
      // Position des Players:
      float playerWidthPosXLeft = player.getX();
      float playerHeightPosLeft = player.getY();
      // Position des Gegners:
      float enemyWidthPosXLeft = enemy.getX();
      float enemyHeightPosYLeft = enemy.getY();
      // Initialisierung der Spieler-Box und Gegner-Box
      PlayerBox =
          new Rectangle(
              playerWidthPosXLeft, playerHeightPosLeft, player.getWidth(), player.getHeight());
      EnemyBox =
          new Rectangle(
              enemyWidthPosXLeft, enemyHeightPosYLeft, enemy.getWidth(), enemy.getHeight());

      // Gegner rendern
      enemy.render(renderer.getSpriteBatch());

      // Kollisionsfunktion zwischen dem Spieler und Gegnern
      BoxCollides(PlayerBox, EnemyBox);
    }

    // Entitys rendern
    for (AbstractEntity entity : poolableEntityList) entity.render(renderer.getSpriteBatch());

    renderer.getSpriteBatch().end();
  }