'How to animate 2d ball through 2d obstacles [closed]

I have a JavaFX obstacle course that my "coin" is to fall down and reach the bottom. If the coin hits the obstacle, it'll go either left or right if there is room.

I have stored the position of the coin in an int array where each odd element is a row and each even element is a column.

int[] positionsOfCoinThroughoutGame

When I run my program. the coin goes through the correct spots by following my int array. However, the coins stay on the screen and don't fully animate. So I am left with a coin in each of the rows the coin travels through. How do I animate this coin so it has a smooth transition from top to bottom? This is my implementation

private class CoinAnimation extends AnimationTimer {

    @Override
    public void handle(long arg0) {
        CoinGen = new Ellipse(coinPositions[getCoinPositionIteration() + 1] * 45,coinPositions[getCoinPositionIteration()] * 45,20,20);
        CoinGen.setFill(Color.YELLOW);
        root.getChildren().add(CoinGen);
        incrimentCoinPositionIteration();
    }
}


Solution 1:[1]

Your approach looks wrong. Instead of constantly creating new coins, which you don't seem to remove too, you should create just one coin and actually move it via the scene graph. That's how JavaFX is supposed to be used.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mipa