0

I'm trying to use a TranslateTransition object in JavaFX to move an onscreen object in a LOGO program I am building. I have an onscreen TurtleDisplay object, which extends ImageView, and this is what I'm trying to move. The code to move it is here:

 public void drawTurtle(TurtleData currentData) {
    TurtleImage inList = getTurtleImage(currentData);

    if (inList==null) {
        TurtleImage temp = new TurtleImage(currentData.getX(),
                currentData.getY(), currentData.getHeading(), turtleImage);
        myTurtlesGroup.getChildren().add(temp);
        myTurtlesList.add(temp);
    }
    else {
        TranslateTransition tt = new TranslateTransition(Duration.seconds(3),inList);
        tt.setFromX(inList.getX());
        tt.setFromY(inList.getY());
        tt.setToX(inList.getX()+currentData.getX());
        tt.setToY(inList.getY()+currentData.getY());
        tt.setCycleCount(Timeline.INDEFINITE);
        tt.play();
    }
}

This code, which is part of the front end, is called from the back end via a Listener on an ObservableList. The backend contains this ObservableList of TurtleData objects that contain the information necessary to move a turtle on screen -- which turtle to move, the coordinate to move to, and the rotation of the turtle. The code to call this is here:

 ObservableList<TurtleData> myTurtles = FXCollections
            .observableArrayList();
    myTurtles.addListener(new ListChangeListener<TurtleData>() {
        @Override
        public void onChanged(Change<? extends TurtleData> c) {
            myDisplay.getSelectedWorkspace().getTV().clearTurtles();
            while (c.next()) {
                for (TurtleData addItem : c.getAddedSubList()) {
                    myDisplay.getSelectedWorkspace().getTV().drawTurtle(addItem);
                }
            }
        }
    });

I have stepped through with a debugger and ensured that this code is called -- specifically, the tt.play() line is run. Nothing moves on screen. Does anyone have any idea what is wrong? Do I need to setup an Animation Timeline? Thank you for any help!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Jeremy
  • 613
  • 1
  • 5
  • 5
  • If `TurtleImage` is a subclass of `ImageView`, `getX()` and `getY()` are probably not doing what you think. However, as long as either `currentData.getX()` or `currentData.getY()` is nonzero, you should see something move. I would check those values, and also ensure that you are getting a reference to the correct image instance (check `inList.getScene()` to make sure you have an image that is part of the scene graph). – James_D Mar 02 '15 at 18:35
  • 2
    It is going to be easier for somebody to answer if you edit your question to [provide minimal sample code](http://stackoverflow.com/help/mcve) which somebody could just copy and paste to execute and run. I will say that your code for drawing the turtles is a little strange and your usage of "front end" and "back end" is pretty vague. On specific advice for using transitions versus timelines versus using an animation timer - there is not enough context in your question to advise on that - you might want to ask a new question for that specifically. – jewelsea Mar 02 '15 at 18:35
  • Perhaps this [sample code which runs new transitions one after the other forever](http://stackoverflow.com/questions/28093416/javafx-transition-animation-waiting), moving a node along a random path might help you understand the animation system better (but maybe not, it is a bit different from your problem and the other problem possibly had an unbounded and dynamic nature which your problem may not have - so a solution to your problem might be simpler). – jewelsea Mar 02 '15 at 18:46

0 Answers0