我想制作一张在背景上移动的图片,但是我只能使一个字母随大小写循环移动。谁能帮我解决我的问题。
最好的问候 马尔特·布克林斯基(Malte Bukrinski)public class FXMain extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
// Parent root = FXMLLoader.load(getClass().getResource("frontierLand.fxml"));
//Image img1 = new Image(new FileInputStream(C:\Users\Malte Bukrinski\Documents\GitHub\Projektarbejde-1.-Semester-Gruppe-05\World of Zuul Project\src\Map_Pictures\Char2.png))
Pane pane = new Pane();
//Image characterPicture = FXMLLoader.load(getClass().getResource("char2");
Text text = new Text(20,20,"A");
Stage stage = new Stage();
Scene scene = new Scene(pane);
pane.getChildren().add(text);
text.setOnKeyPressed(e -> { //Lambda expression
switch(e.getCode()){
case DOWN: text.setY(text.getY() + 50); break;
case UP: text.setY(text.getY() - 50); break;
case LEFT: text.setX(text.getX()- 50); break;
case RIGHT: text.setX(text.getX()+ 50); break;
default:
if(e.getText().length() > 0)
{
text.setText(e.getText());
}
}
});
primaryStage.setTitle("Kagearm");
primaryStage.setScene(scene);
primaryStage.show();
//stage.setTitle("FrontierLand");
//stage.setScene(scene);
//stage.show();
text.requestFocus();
}
public static void main(String[] args) {
launch(args);
}
}
答案 0 :(得分:0)
您可以在画布上或javaFX的imageView中绘制图像,如果您想在示例中将其绘制为像文本一样的图像,则为imageView
还要将onKeyPressed绑定到场景中
name = input("What is your full name? ")
print(name[0] + name[len(name)-1])