コード例 #1
0
ファイル: TileMapRenderer.java プロジェクト: eerock/libgdx
  private int addBlock(int[][] layer, int layerNum, int blockRow, int blockCol, boolean blended) {
    int tile;
    AtlasRegion region;
    cache.beginCache();

    int firstCol = blockCol * tilesPerBlockX;
    int firstRow = blockRow * tilesPerBlockY;
    int lastCol = firstCol + tilesPerBlockX;
    int lastRow = firstRow + tilesPerBlockY;

    int row, col;
    float x, y;

    for (row = firstRow; row < lastRow && row < layer.length; row++) {
      for (col = firstCol; col < lastCol && col < layer[row].length; col++) {
        tile = layer[row][col];
        if (tile != 0) {
          if (blended == blendedTiles.contains(tile)) {
            region = atlas.getRegion(tile);
            if (region != null) {
              y = (layer.length - row) * tileHeight - (region.packedHeight + region.offsetY);
              x = col * tileWidth + region.offsetX;
              cache.add(region, x, y);
            }
          }
        }
      }
    }

    return cache.endCache();
  }
コード例 #2
0
ファイル: TileMapRenderer.java プロジェクト: eerock/libgdx
  /**
   * 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);
  }
コード例 #3
0
ファイル: RenderLayers.java プロジェクト: Jobao/Harvest-Life
  /**
   * Carga los layers desde el arrayList
   *
   * @param maplayers un conjunto de layers que se dibujaran en el mismo orden que esten en el
   *     ArrayList
   */
  public void Cargar(ArrayList<TiledLayer> maplayers) {

    texture = new Texture(Gdx.files.internal("gfx/Tiles/ambiente.png"));

    for (int i = 0; i < LAYERS; i++) {
      caches[i] = new SpriteCache();
      cache = caches[i];
      cache.beginCache();
      for (int y = 0; y < HEIGHT; y++) {
        for (int x = 0; x < WIDTH; x++) {
          int textureX = maplayers.get(i).tiles[y][x] % 16;
          int textureY = maplayers.get(i).tiles[y][x] / 16;
          if (textureX != 0 || textureY != 0) {
            int tileX = x * TILE_SIZE;
            int tileY = ((HEIGHT - y) * TILE_SIZE);

            cache.add(
                texture,
                tileX,
                tileY,
                textureX * (TILE_SIZE),
                textureY * (TILE_SIZE),
                TILE_SIZE,
                TILE_SIZE);
          }
        }
      }

      layers[i] = cache.endCache();
    }
  }
コード例 #4
0
ファイル: DeathGame.java プロジェクト: 0x17/DeathJam
  private void initBackground() {
    backCache = new SpriteCache();
    backCache.beginCache();

    TextureRegion backRegion = Globals.atlas.findRegion("back");

    float w = backRegion.getRegionWidth() * 2;
    float h = backRegion.getRegionWidth() * 2;

    for (int y = 0; y < Globals.PSCR_H; y += h)
      for (int x = 0; x < Globals.PSCR_W; x += w) backCache.add(backRegion, x, y, w, h);

    backCacheId = backCache.endCache();
  }
コード例 #5
0
ファイル: DeathGame.java プロジェクト: 0x17/DeathJam
  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();
  }
コード例 #6
0
  /**
   * 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);
  }
コード例 #7
0
ファイル: RenderLayers.java プロジェクト: Jobao/Harvest-Life
  /** 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();
    }
  }
コード例 #8
0
ファイル: TiledMap.java プロジェクト: Khazrak/mini2Dx
  /**
   * Constructs a map from a TMX file
   *
   * @param fileHandle A {@link FileHandle} to a .tmx file
   * @param loadTilesets True if the tileset images should be loaded
   * @throws IOException Thrown if the map file could not be parsed
   */
  public TiledMap(FileHandle fileHandle, boolean loadTilesets) throws IOException {
    this();
    this.loadTilesets = loadTilesets;
    this.fileHandle = fileHandle;

    TiledParser parser = new TiledParser();
    parser.addListener(this);
    parser.parse(fileHandle);

    if (loadTilesets) {
      layerCache = new SpriteCache(getWidth() * getHeight() * tileLayers.size(), true);
      for (int layer = 0; layer < tileLayers.size(); layer++) {
        layerCache.beginCache();
        for (int y = 0; y < getHeight(); y++) {
          for (int x = 0; x < getWidth(); x++) {
            int tileId = tileLayers.get(layer).getTileId(x, y);

            if (tileId > 0) {
              int tileRenderX = x * getTileWidth();
              int tileRenderY = y * getTileHeight();

              for (int i = 0; i < tilesets.size(); i++) {
                Tileset tileset = tilesets.get(i);
                if (tileset.contains(tileId)) {
                  layerCache.add(tileset.getTile(tileId).getTileImage(), tileRenderX, tileRenderY);
                  break;
                }
              }
            }
          }
        }
        int layerCacheId = layerCache.endCache();
        layerCacheIds.put(tileLayers.get(layer), layerCacheId);
      }
    }
  }
コード例 #9
0
ファイル: TileMapRenderer.java プロジェクト: eerock/libgdx
 /** Releases all resources held by this TiledMapRenderer. */
 public void dispose() {
   cache.dispose();
 }
コード例 #10
0
ファイル: TileMapRenderer.java プロジェクト: eerock/libgdx
 public Matrix4 getTransformMatrix() {
   return cache.getTransformMatrix();
 }
コード例 #11
0
ファイル: TileMapRenderer.java プロジェクト: eerock/libgdx
 public Matrix4 getProjectionMatrix() {
   return cache.getProjectionMatrix();
 }
コード例 #12
0
 /** Releases all resources held by this TiledMapRenderer. */
 @Override
 public void dispose() {
   cache.dispose();
 }
コード例 #13
0
  private int addBlock(int[][] layer, int blockRow, int blockCol, boolean blended) {
    cache.beginCache();

    int firstCol = blockCol * tilesPerBlockX;
    int firstRow = blockRow * tilesPerBlockY;
    int lastCol = firstCol + tilesPerBlockX;
    int lastRow = firstRow + tilesPerBlockY;

    float offsetX = ((tileWidth - unitsPerTileX) / 2);
    float offsetY = ((tileHeight - unitsPerTileY) / 2);

    for (int row = firstRow; row < lastRow && row < layer.length; row++) {
      for (int col = firstCol; col < lastCol && col < layer[row].length; col++) {
        int tile = layer[row][col];

        boolean flipX = ((tile & FLAG_FLIP_X) != 0);
        boolean flipY = ((tile & FLAG_FLIP_Y) != 0);
        boolean rotate = ((tile & FLAG_ROTATE) != 0);

        tile = tile & ~MASK_CLEAR;

        if (tile != 0) {
          if (blended == blendedTiles.contains(tile)) {
            TextureRegion reg = atlas.getRegion(tile);
            if (reg != null) {

              float x = col * unitsPerTileX - offsetX;
              float y = (layer.length - row - 1) * unitsPerTileY - offsetY;
              float width = reg.getRegionWidth();
              float height = reg.getRegionHeight();
              float originX = width * 0.5f;
              float originY = height * 0.5f;
              float scaleX = unitsPerTileX / tileWidth;
              float scaleY = unitsPerTileY / tileHeight;
              float rotation = 0;
              int sourceX = reg.getRegionX();
              int sourceY = reg.getRegionY();
              int sourceWidth = reg.getRegionWidth();
              int sourceHeight = reg.getRegionHeight();

              if (rotate) {
                if (flipX && flipY) {
                  rotation = -90;
                  sourceX += sourceWidth;
                  sourceWidth = -sourceWidth;
                } else if (flipX && !flipY) {
                  rotation = -90;
                } else if (flipY && !flipX) {
                  rotation = +90;
                } else if (!flipY && !flipX) {
                  rotation = -90;
                  sourceY += sourceHeight;
                  sourceHeight = -sourceHeight;
                }
              } else {
                if (flipX) {
                  sourceX += sourceWidth;
                  sourceWidth = -sourceWidth;
                }
                if (flipY) {
                  sourceY += sourceHeight;
                  sourceHeight = -sourceHeight;
                }
              }

              cache.add(
                  reg.getTexture(),
                  x,
                  y,
                  originX,
                  originY,
                  width,
                  height,
                  scaleX,
                  scaleY,
                  rotation,
                  sourceX,
                  sourceY,
                  sourceWidth,
                  sourceHeight,
                  false,
                  false);
            }
          }
        }
      }
    }

    return cache.endCache();
  }