我正在尝试使用JavaFX编写拼图游戏,部分原因是有人问我,部分是因为我想给JavaFX一个机会.但是,我对图像的实际裁剪有困难.
该想法是供用户提供图像和程序以将图像切割成更小的片段.简单吧?我的问题是:我能找到切割图像的唯一方法是制作图像对象的副本并更改副本的可见部分,这是一个例子:
ImageView imgageView = new ImageView(); // Creates a new ImageView; this will be a single puzzle piece.
imgageView.setImage(originalImage); // Use the original image as the "base."
Rectangle2D rectangle = new Rectangle2D(0, 0, 50, 50); // Crop the image from (0,0) to (50, 50).
Run Code Online (Sandbox Code Playgroud)
public Rectangle2D(double minX,
double minY,
double width,
double height)
Creates a new instance of Rectangle2D.
Parameters:
minX - The x coordinate of the upper-left corner of the Rectangle2D
minY - …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 JavaFX 在登录窗口(舞台)内创建一个精灵动画,一旦用户获得登录和密码信息,就会播放该动画。我尝试使用 Michael Heinrichs 在他关于使用 JavaFX 精灵动画的博客文章中发布的类,但我无法让它工作,主要是因为我不明白如何在不使用 start 方法的情况下在 ImageView 中创建这个动画(在我的情况下也不起作用)。
这是我在登录阶段的 FXML 文件中的代码:
<GridPane alignment="CENTER" hgap="10.0" vgap="10.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="crud.controller.MainController">
<padding>
<Insets bottom="25.0" left="25.0" right="25.0" top="25.0" />
</padding>
<children>
<ImageView fx:id="loginAnimationImageView" GridPane.columnIndex="0" GridPane.halignment="CENTER" GridPane.columnSpan="2" GridPane.rowIndex="0">
<image>
<Image url="@../assets/shop-sprite.png" />
</image>
<viewport>
<Rectangle2D height="130.0" width="131.0" />
</viewport>
</ImageView>
<Label text="Usuario" GridPane.columnIndex="0" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
<TextField fx:id="loginTextField" onAction="#onEnterTextFieldAction" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Contraseña" GridPane.columnIndex="0" GridPane.rowIndex="3" />
<PasswordField fx:id="passwordTextField" onAction="#onEnterPasswordFieldAction" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Button fx:id="loginButton" onAction="#loginButtonAction" text="Ingresar" …Run Code Online (Sandbox Code Playgroud) 我正在用 JavaFX 搞游戏编程,我为图形制作了一个 spritesheet。目前,我正在将 JavaFX 更改Image为 a BufferedImage,然后使用该BufferedImage#subImage函数获取子图像,然后使用SwingFXUtils将其更改回 JavaFX Image。我试图寻找一种更简单的方法,但还没有找到。他们是获取 JavaFX 子映像的更简单方法吗?