我有一个脚本,绘制一个六边形瓷砖的游戏板。我想为每个瓷砖添加一个InnerShadow效果,但我也希望每个瓷砖都有一个半透明的背景。正常阴影应位于透明背景的顶部(如果有意义)。由于某些我不知道的原因,阴影显示为伪影。如果我从图块中删除setFill,它会自动显示黑色背景。在屏幕截图中,小白点是我所说的工件。我做错了什么?
经过进一步调查,我意识到白点实际上是图像的一部分。但是InnerShadow没有出现的问题仍然存在。所以我改变了问题的标题。如何在多边形中添加InnerShadow和透明背景?
private void drawHexGridLoop(GraphicsContext g, Point origin, int size, int radius, int padding, boolean blank) {
String rsrc;
double ang30 = Math.toRadians(30);
double xOff = Math.cos(ang30) * (radius + padding);
double yOff = Math.sin(ang30) * (radius + padding);
int half = size / 2;
int i = 0;
for (int row = 0; row < size; row++) {
int cols = size - java.lang.Math.abs(row - half);
for (int col = 0; col < cols; col++) {
int xLbl = row < half ? col - row : col - half;
int yLbl = row - half;
int x = (int) (origin.x + xOff * (col * 2 + 1 - cols));
int y = (int) (origin.y + yOff * (row - half) * 3);
Hexagon hex = new Hexagon(x, y, radius);
int diceNum = diceSpaces.get(i);
if(!blank){
rsrc = resources.get(i);
} else {
rsrc = null;
}
//hex.draw(g, x, y, diceNum, rsrc);
Polygon tile = new Polygon();
for(int p = 0; p < hex.xpoints.length; p++){
double xpoint = hex.xpoints[p];
tile.getPoints().add(xpoint);
double ypoint = hex.ypoints[p];
tile.getPoints().add(ypoint);
}
tile.setFill(Color.web("rgba(255, 255, 255, 0.3)"));
InnerShadow innerShadow = new InnerShadow(5, Color.WHITE);
innerShadow.setOffsetX(4);
innerShadow.setOffsetY(4);
tile.setEffect(innerShadow);
wrapperPane.getChildren().add(tile);
tiles[i] = new Tile(i, xLbl, yLbl, rsrc, diceSpaces.get(i), hex.xpoints, hex.ypoints);
i++;
}
}
}