Пример #1
0
  /**
   * Renders specific layers between the given Tiled world coordinates.
   *
   * @param x The x coordinate to start drawing (in pixels)
   * @param y the y coordinate to start drawing (in pixels)
   * @param width the width of the tiles to draw (in pixels)
   * @param height the width of the tiles to draw (in pixels)
   * @param layers The list of layers to draw, 0 being the lowest layer. You will get an
   *     IndexOutOfBoundsException if a layer number is too high.
   */
  public void render(float x, float y, int width, int height, int[] layers) {
    lastRow = (int) ((mapHeightPixels - (y - height + overdrawY)) / (tilesPerBlockY * tileHeight));
    initialRow = (int) ((mapHeightPixels - (y - overdrawY)) / (tilesPerBlockY * tileHeight));
    initialRow = (initialRow > 0) ? initialRow : 0; // Clamp initial Row > 0

    initialCol = (int) ((x - overdrawX) / (tilesPerBlockX * tileWidth));
    initialCol = (initialCol > 0) ? initialCol : 0; // Clamp initial Col > 0
    lastCol = (int) ((x + width + overdrawX) / (tilesPerBlockX * tileWidth));

    Gdx.gl.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    cache.begin();
    for (currentLayer = 0; currentLayer < layers.length; currentLayer++) {
      for (currentRow = initialRow;
          currentRow <= lastRow && currentRow < getLayerHeightInBlocks(currentLayer);
          currentRow++) {
        for (currentCol = initialCol;
            currentCol <= lastCol && currentCol < getLayerWidthInBlocks(currentLayer, currentRow);
            currentCol++) {
          Gdx.gl.glDisable(GL10.GL_BLEND);
          cache.draw(normalCacheId[layers[currentLayer]][currentRow][currentCol]);
          Gdx.gl.glEnable(GL10.GL_BLEND);
          cache.draw(blendedCacheId[layers[currentLayer]][currentRow][currentCol]);
        }
      }
    }
    cache.end();
    Gdx.gl.glDisable(GL10.GL_BLEND);
  }
Пример #2
0
  private void renderScene() {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    backCache.begin();
    backCache.draw(backCacheId);
    backCache.end();

    Matrix4 mviewmx = scroller.cam.view;

    world.render(mviewmx);
    renderPlayer(mviewmx);

    renderTextOverlay();
  }
  /**
   * Renders specific layers between the given bounding box in map units.
   *
   * @param x The x coordinate to start drawing
   * @param y the y coordinate to start drawing
   * @param width the width of the tiles to draw
   * @param height the width of the tiles to draw
   * @param layers The list of layers to draw, 0 being the lowest layer. You will get an
   *     IndexOutOfBoundsException if a layer number is too high.
   */
  public void render(float x, float y, float width, float height, int[] layers) {
    lastRow = (int) ((mapHeightUnits - (y - height + overdrawY)) / (unitsPerBlockY));
    initialRow = (int) ((mapHeightUnits - (y - overdrawY)) / (unitsPerBlockY));
    initialRow = (initialRow > 0) ? initialRow : 0; // Clamp initial Row > 0

    lastCol = (int) ((x + width + overdrawX) / (unitsPerBlockX));
    initialCol = (int) ((x - overdrawX) / (unitsPerBlockX));
    initialCol = (initialCol > 0) ? initialCol : 0; // Clamp initial Col > 0

    Gdx.gl.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    cache.begin();
    if (isSimpleTileAtlas) {
      // Without this special case the top left corner doesn't work properly on mutilayered maps
      Gdx.gl.glEnable(GL10.GL_BLEND);
      for (currentLayer = 0; currentLayer < layers.length; currentLayer++) {
        for (currentRow = initialRow;
            currentRow <= lastRow && currentRow < getLayerHeightInBlocks(currentLayer);
            currentRow++) {
          for (currentCol = initialCol;
              currentCol <= lastCol && currentCol < getLayerWidthInBlocks(currentLayer, currentRow);
              currentCol++) {
            cache.draw(blendedCacheId[layers[currentLayer]][currentRow][currentCol]);
          }
        }
      }
    } else {
      for (currentLayer = 0; currentLayer < layers.length; currentLayer++) {
        for (currentRow = initialRow;
            currentRow <= lastRow && currentRow < getLayerHeightInBlocks(currentLayer);
            currentRow++) {
          for (currentCol = initialCol;
              currentCol <= lastCol && currentCol < getLayerWidthInBlocks(currentLayer, currentRow);
              currentCol++) {
            Gdx.gl.glDisable(GL10.GL_BLEND);
            cache.draw(normalCacheId[layers[currentLayer]][currentRow][currentCol]);
            Gdx.gl.glEnable(GL10.GL_BLEND);
            cache.draw(blendedCacheId[layers[currentLayer]][currentRow][currentCol]);
          }
        }
      }
    }
    cache.end();
    Gdx.gl.glDisable(GL10.GL_BLEND);
  }
Пример #4
0
  /** Dibuja en pantalla, lo que se cargo previamente en el metodo cargar, de esta clase. */
  public void Render() {
    GL10 gl = Gdx.gl10;
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    for (int i = 0; i < LAYERS; i++) {
      SpriteCache cache = caches[i];
      cache.setProjectionMatrix(cam.combined);
      cache.begin();
      for (int j = 0; j < TILES_PER_LAYER; j += BLOCK_TILES) {
        cache.draw(layers[i], j, BLOCK_TILES);
      }
      cache.end();
    }

    if (System.nanoTime() - startTime >= 1000000000) {
      // Gdx.app.log("TileTest", "fps: " + Gdx.graphics.getFramesPerSecond());
      startTime = System.nanoTime();
    }
  }