0

Need to create coins that exist for several seconds and then disappear.

The coins are supposed stay in place but move vertically just barely enough to be noticed.

I tried using TranslateTransition for the motion but the coins just disappear.

My class for Coin looks like this.

private Group body;
Circle r0;
Circle inner;
TranslateTransition transy;

public Coin(double x, double y) {

    r0 = new Circle(20.0d);
    inner = new Circle(10.0d);

    r0.setFill(Color.GOLD);
    r0.setStroke(Color.BLACK);
    r0.setStrokeWidth(1.2d);

    inner.setFill(Color.SILVER);
    inner.setStroke(Color.BLACK);
    inner.setStrokeWidth(0.2d);

    this.body = new Group(new Node[]{this.r0, this.inner});
    getChildren().add(body);

    setTranslateX(x);
    setTranslateY(y);


    transy= new TranslateTransition();
    transy = new TranslateTransition(Duration.seconds(1.0d),this.body);
    transy.setFromY(y);
    transy.setToY(y+3);
    transy.setAutoReverse(true);
    transy.setCycleCount(-1);
    transy.play();

}

The main class is supposed to call a constructor for Coin at random and put them in random positions on the edges of the screen.

John Young
  • 57
  • 1
  • 1
  • 4

0 Answers0