Sjoerd Brauer
Sjoerd Brauer

Reputation: 129

Java fx slowly moving image

Currently i'm trying to make an image slowly slide using Java fx from one coordinate to another. For this construction i'm using a pane and have added a shaft imageview and a elevator image to it. I've been succesfull in changing the coordinates of the image but I want the image to slowly slide over to that position. As a result I added a loop that with a thread.sleep method to slow down the looping speed. Unforunately this does not give the desired effect.

Hopefully one of you has a good suggestion I could use for this. My loop:

    Button een = new Button("1");
    een.setOnAction(new EventHandler<ActionEvent>(){

        @Override
        public void handle(ActionEvent event) {
            if(elevator.getY()>300){
                while(elevator.getY()!=300){

                    elevator.setY(elevator.getY()-1);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(LayoutSample.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }

    });

Yours truly

Upvotes: 0

Views: 272

Answers (1)

jewelsea
jewelsea

Reputation: 159341

No loops, no sleep, TranslateTransition, linked javadoc includes a sample.

Upvotes: 1

Related Questions