我正在将多边形渲染到屏幕上,但是当我使用fillRect清除方法开头的BufferedImage时,什么都没有显示。使用fillRect方法确实可以在我的一个相同类型的对象中显示事物,而在另一个相同类型的对象中却没有。
我已经尝试将方法w / fillPolygon放在与filLRect方法相同的方法中,但是没有用。我尝试从Graphics2D对象和alpha合成中删除RenderingHints。
private void projectMap() {
// Makes the entire screen black before reprojecting!
g2d.setColor(Color.BLACK);
g2d.fillRect(0,0,image.getWidth(), image.getHeight());
for(int i = 0; i < orderedChunks.size(); i++) {
Chunk ic = orderedChunks.get(i);
orderParts(ic);
for(int j = 0; j < orderedParts.size(); j++) {
Part ip = orderedParts.get(j);
projectPart(ic.getX(), ic.getZ(), ip);
}
}
}
// Assuming that projCornersX and projCornersY have values stored in them. Many lines of this code have been removed.
private void projectPart(int chunkX, int chunkZ, Part part) {
BufferedImage image = part.getImage();
int orient = part.getOrient();
int x = part.getX();
int y = part.getY();
int width = part.getWidth();
int length = part.getLength();
int displacement = part.getDisplacement();
int componentIndex = part.getComponentIndex();
int curX = 0;
int curY = 0;
int curZ = 0;
if(orient==0) {
curY = componentIndex * Main.IMAGE_SIZE + displacement;
}
for(int ix = 0; ix < width; ix++) {
if(orient==0) {
curX = chunkX * Main.IMAGE_SIZE + x + ix;
}
for(int iy = 0; iy < length; iy++) {
if(hasIndexWithinImage(projCornersX, projCornersY)) {
g2d.setColor(new Color(image.getRGB(ix, iy)));
g2d.fillPolygon(projCornersX, projCornersY, 4);
}
}
}
}
我会得到黑色背景,但我希望显示多边形,因为fillPolygon方法位于fillRect方法之后。
请注意,所有对象均已初始化。