Ejemplo n.º 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);
        }
      }
    }
  }
Ejemplo n.º 2
0
 protected void processTouchPressed() {
   if (!input.isMoving()) {
     int posx = 0;
     int posy = 0;
     if (getContainer() == null) {
       posx = (int) ((getX() + input.getTouchX()) / blockSize);
       posy = (int) ((getY() + input.getTouchY()) / blockSize);
     } else {
       posx = (int) ((getContainer().getX() + getX() + input.getTouchX()) / blockSize);
       posy = (int) ((getContainer().getY() + getY() + input.getTouchY()) / blockSize);
     }
     mapId = fied2d.getType(posx, posy);
     super.processTouchPressed();
   }
 }