0
我有一個關於JavaFX的問題。我自學了Java,現在我正在學習JavaFX。更新StackPane上的精靈的位置JavaFX
我一直在嘗試更新屏幕上50x50黑塊的位置。我有一個YAxis變量,當我改變了塊的位置。
我希望塊「流」下類似於俄羅斯方塊的屏幕。
我的代碼是凌亂的,因爲我只是瞎搞吧,所以請原諒的是:
package gamefx;
import javafx.animation.Animation;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class GameFX extends Application {
public Image img = new Image("Block1.png");
public ImageView image = new ImageView(img);
public int YAxis = -200;
@Override
public void start(Stage primaryStage) throws InterruptedException{
primaryStage.setTitle("Game");
StackPane stckp1 = new StackPane();
Scene scn = new Scene(stckp1, 700, 700);
primaryStage.setScene(scn);
primaryStage.show();
image.setTranslateY(YAxis);
stckp1.getChildren().add(image);
}
}
非常感謝,這對我們有很大的幫助。我也改名爲yAxis,謝謝:) – DRH1469