1
I’m having a problem setting the x and y position of an Imageview in a Javafx Pane. It is a loop code and, the first time the method is called, it arrow the img object at the specific coordinates (last two lines), but from the second time, Java ignores this position. Here is the code:
private void embarque_para_vagao(){
int dif, aux, dif2;
if(Integer.parseInt(nome) <= 4 ){
aux = Integer.parseInt(nome);
dif = -40;
dif2 = 5 - Integer.parseInt(nome);
}
else{
aux = Integer.parseInt(nome)-4;
dif = 75;
dif2 = Integer.parseInt(nome)-1;
}
PathTransition entra_fila = new PathTransition();
entra_fila.setNode(img);
entra_fila.setDuration( Duration.seconds( TempoEmbarque ) );
Polyline line = new Polyline(
60+42*(aux+dif2), -210-42*3,
60+42*(aux+dif2-vagao.CadeirasOcupadas), -210-42*3,
60+42*(aux+dif2-vagao.CadeirasOcupadas), -210-42*4
);
entra_fila.setPath(line);
entra_fila.play();
while(entra_fila.getStatus() == Animation.Status.RUNNING){
System.out.println(entra_fila.getStatus());
}
Platform.runLater(() -> {
ancVagao.getChildren().add(img);
});
img.setX(-188);
img.setY(-70);
}
From what I understand you must be wanting to make a kind of game, moving the image across the screen. Maybe using Canvas this comes out easier. It also seems to me that you are adding the same image several times as ancVagao’s daughter.
– Gustavo Fragoso