作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个棋盘游戏(首先移植到 JavaFX),其中玩家必须通过循环杀死对手的棋子。
以上内容是在 Surakurta(Permanin 的另一个名称)的维基百科页面上提供的。但是,我只能构建这种类型的网格:
如何在拐角处创建这些环形交叉口?
已构建网格的实现细节:GridPane 填充了 36 个 BoardInput 扩展 javafx.scene.control.Button
对象。这些对象很特殊,因为它们自动创建一个带有三个 BackgroundFill
对象的 Background
- 水平线、垂直线和卵石圆形填充。
最佳答案
使用路径
。 ArcTo
元素允许您创建圆形零件。 HLineTo
、VLineTo
和 ClosePath
可用于直线部分:
此外,我不建议使用BackgroundFill
。我更喜欢在面板视觉效果上覆盖不可见按钮或为 GridPane
本身处理 MouseEvent
。
private static ArcTo createArc(double radius, double dx, double dy) {
ArcTo result = new ArcTo(radius, radius, 0, dx, dy, true, true);
result.setAbsolute(false);
return result;
}
private static HLineTo createHLine(double length) {
HLineTo result = new HLineTo(length);
result.setAbsolute(false);
return result;
}
private static VLineTo createVLine(double length) {
VLineTo result = new VLineTo(length);
result.setAbsolute(false);
return result;
}
private static Path createPath(double radius, double midSize, Color storke) {
final double lineLength = 2 * radius + midSize;
Path result = new Path(
new MoveTo(radius, 2 * radius), // start at left end of top horizontal line
createArc(radius, radius, -radius), // top left loop
createVLine(lineLength), // down
createArc(radius, -radius, -radius), // bottom left loop
createHLine(lineLength), // right
createArc(radius, -radius, radius), // bottom right loop
createVLine(-lineLength), // up
createArc(radius, radius, radius),
new ClosePath() // left
);
result.setStroke(storke);
result.setStrokeWidth(10);
return result;
}
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new StackPane(
createPath(100, 50, Color.GREEN),
createPath(50, 150, Color.AQUA)
));
primaryStage.setScene(scene);
primaryStage.show();
}
输出
关于JavaFX:使用 Permanin 扭曲创建板网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52113774/
我正在创建一个棋盘游戏(首先移植到 JavaFX),其中玩家必须通过循环杀死对手的棋子。 以上内容是在 Surakurta(Permanin 的另一个名称)的维基百科页面上提供的。但是,我只能构建这种
我是一名优秀的程序员,十分优秀!