问题描述
所以问题是我正在用Java制作国际象棋游戏,并且棋盘由矩形组成,并用setFill()方法着色。当我尝试使用此方法将棋子的透明图像放在图块上时,它将覆盖之前的setFill(),因此图块的颜色将被删除。它看起来像这样: board
我找不到其他功能来将图像设置为矩形。
代码:
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
public class Tile extends StackPane {
int xCoordinate;
int yCoordinate;
Rectangle border = new Rectangle(80,80);
public static boolean darkTile=false;
public Tile(int xCoordinate,int yCoordinate){
if(darkTile==false){
border.setFill(Color.BEIGE);
}
else{
border.setFill(Color.broWN);
}
border.setstroke(Color.BLACK);
getChildren().addAll(border);
}
public void addImage(Image img){
this.border.setFill(new ImagePattern(img));
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)