Java Graphics - Рисование нескольких изображений рядом друг с другом создает пустые линииJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Java Graphics - Рисование нескольких изображений рядом друг с другом создает пустые линии

Сообщение Anonymous »

Я пытаюсь нарисовать карту моей игры, у нее есть объект плитки с местоположением X & Y. Изображение плиток удерживается 1 классом, и я изменяю их размер после того, как закончил масштаб. Zoom - это 0, кажется, что все в порядке, но когда я перемещаю мышь, эта ошибка, которая нажимает. (Поскольку камера движется в зависимости от расстояния мыши от центра) PrettyPrint-Override ">

Код: Выделить всё

public class GameScreen extends JPanel {

private static GameScreen INSTANCE;
private static Graphics2D graphics2D;

private List painters = new ArrayList();

public GameScreen() {
INSTANCE = this;
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
graphics2D = (Graphics2D) g;
graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

for (ScreenPainter painter : painters) painter.paint();
for (BAText text : new ArrayList(TextRegistry.getTexts().values())) {
if (text != null) text.drawText(graphics2D);
}

//if (BlueArchangels.STATE == GameState.PAUSE) MenuRegistry.getExitMenu().paint(graphics);

graphics2D.dispose();
}

public void updatePainters() {
painters = new ArrayList(ScreenPainterManager.getPainters());
}

public static GameScreen INSTANCE() {
return INSTANCE;
}

public static Graphics2D getGraphics2D() {
return graphics2D;
}
}
Метод в mappainter class
@Override
public void paint() {
if (grids == null) {
assignValue();
return;
}

double cellWidth = getCellWidth(), cellHeight = getCellHeight();
boolean zooming = Camera.zooming();

for (Map.TileGrid tileGrid : grids) {
int offsetX = tileGrid.getOffsetX(), offsetY = tileGrid.getOffsetY();

for (Map.Tile tile : tileGrid.getAllTiles()) {
BufferedImage image = tile.getTileImage();
if (image == null) continue;

double width = cellWidth, height = cellHeight;
double x = width * (tile.x + offsetX), y = height * (-tile.y - offsetY);

AffineTransform transform = new AffineTransform();

// Ground tiles are already at the same size as the cell.
if (!tile.isGround()) {
double w = image.getWidth(), h = image.getHeight();
// Check how many times the cell stays inside the image, to scale it later.
double timesX = w / width, timesY = h / height;

// Calculate the target size of the tile.
width = width * timesX;
height = height * timesY;

// Scale the size to the target size.
transform.scale(width / w, height / h);

// Now with the target size, we calculate the exact location to place it in its cell at (x; y).
// Otherwise, when scaled it will be placed on another cell and not its original.

// Now we correct the position by placing the x coordinate and
// the bottom part of the tile in the middle of the cell.
x += -(width / 2D) + (cellWidth / 2D);
y += -height + (cellHeight / 2D);
}

if (Camera.isOutCamera(x, y, width, height)) continue;

if (zooming) {
// If zooming and the tile is ground, scale it to the correct size while waiting for resizing.
if (tile.isGround()) {
//transform.scale(width / image.getWidth(), height / image.getHeight());
x += -(width / 2) + (cellWidth / 2);
y += -(height / 2) + (cellHeight / 2);
}
wasZooming = true;
} else {
// Once the game is no more zooming, update the ground tile sizes and draw them without scaling.
if (wasZooming) resizeMapTiles();
wasZooming = false;
}
transform.translate(Camera.toX(x), Camera.toY(y));

if (zooming) {
// If zooming and the tile is ground, scale it to the correct size while waiting for resizing.
if (tile.isGround()) transform.scale(width / image.getWidth(), height / image.getHeight());

}

int degrees = tile.getRotation();
if (degrees != 0) transform.rotate(Math.toRadians(degrees), width / 2D, height / 2D);

ScreenPainter.drawImage(image, transform);
}
}
}

< /code>
Есть идеи о том, почему это происходит? Видео проблемы < /p>
Изменить 1 < /h1>
Я нашел основную проблему этих строк. (Из того, что я проверил) проблема? Является ли проблема рендеринга? Проблема за округление?


Подробнее здесь: https://stackoverflow.com/questions/792 ... mpty-lines
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»