Example #1
0
  public void draw(SpriteBatch batch, int x, int y) {
    int windowX = x + getWidth();
    int windowY = y + getHeight();
    int tempX;
    int tempY;

    int minCol = -(x / blockSize);
    int maxCol = (minCol + ((windowX + (blockSize * 2)) / blockSize));
    if (minCol < 0) {
      minCol = 0;
    }
    if (maxCol < 0) {
      maxCol = 0;
    }
    if (maxCol > fied2d.getHeight()) {
      maxCol = fied2d.getHeight();
    }
    if (minCol > maxCol) {
      minCol = maxCol;
    }

    int minRow = -(y / blockSize);
    int maxRow = (minRow + ((windowY + (blockSize * 2)) / blockSize));
    if (minRow < 0) {
      minRow = 0;
    }
    if (maxRow < 0) {
      maxRow = 0;
    }
    if (maxRow > fied2d.getWidth()) {
      maxRow = fied2d.getWidth();
    }
    if (minRow > maxRow) {
      minRow = maxRow;
    }
    batch.draw(background, x, y, getWidth(), getHeight());
    for (int row = minRow; row < maxRow; row++) {
      for (int col = minCol; col < maxCol; col++) {
        tempX = (x + (col * blockSize));
        tempY = (y + (row * blockSize));
        int id = fied2d.getType(col, row) - 1;
        if (id != -1) {
          texture.animate(id);
          texture.update(tempX, tempY, blockSize, blockSize);
          texture.draw(batch, windowX, windowY);
        }
        if (grid) {
          batch.drawRect(tempX, tempY, blockSize, blockSize);
        }
      }
    }
  }
Example #2
0
 public LMap2D(
     String datafile,
     String mapFile,
     int x,
     int y,
     int width,
     int height,
     int rowTileWidth,
     int colTileHeight,
     int tileSize)
     throws IOException {
   super(x, y, width, height);
   int[][] maps = TileMapConfig.loadJustArray(datafile);
   this.blockSize = tileSize;
   if (background == null) {
     LMap2D.background = TextureUtils.createTexture(1, 1, LColor.black);
   }
   this.fied2d = new Field2D(maps);
   this.texture = new SpriteBatchSheet(mapFile, rowTileWidth, colTileHeight, 0);
   this.batch = new SpriteBatch();
   this.setElastic(true);
   this.setLocked(true);
   this.setLayer(100);
   if (width == 0 || height == 0) {
     setWidth(fied2d.getHeight() * blockSize);
     setHeight(fied2d.getWidth() * blockSize);
   }
 }
Example #3
0
 public int getMapPixelWidth() {
   return (int) blockSize * fied2d.getHeight();
 }