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(); }
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(); }