1

Hi I am a beginner using javaFX.

I displayed some tiles on a pane to represent a map.

I added some circles on the map, and with an asynchronous update function, I update the circle position.

On circles position updates I see a white flicker in the area which is redrawn I suppose.

Here is an illustration of the phenomenon : video of javaFx circle position update flicker

Here is the positionTicker (white circles) :

public class Ticker {

    Position position;
    Circle tickerCircle;

    public Ticker(Position position) {
        this.tickerCircle = new Circle(position.xPos, position.yPos, 5);
        this.tickerCircle.setFill(Color.LIGHTGRAY);

        this.position = position;
        position.SetOnChangeFunction((int newX, int newY) -> {
            this.tickerCircle.setCenterX(newX);
            this.tickerCircle.setCenterY(newY);
        });
    }

    public Circle getTickerNode() {
        return tickerCircle;
    }
}

Here is the code to update these tickers :

    private void startRegularUpdates() {
        final Runnable positionUpdater = new Runnable() {
            public void run() {
                logger.trace("position updater received fake update");
                Optional<Position> posToUpdate = getRandomPosition();
                posToUpdate.ifPresent(pos -> updatePosition(pos));
            }
        };
        positionUpdaterHandle = scheduler.scheduleAtFixedRate(positionUpdater, 1, 10, MILLISECONDS);
    }

And finally the code to add these tickers to a display pane (I execute this statement on all :

    public void AddShapeOnMap(Node shape) {
        this.tileMap.getChildren().add(shape);
    }

Disclaimer : This question may need some work do not hesitate to help me get it right.

Does someone know what may cause that white flicker around the circles when they change position ?

Thanks in advance for your help.

Antonin
  • 879
  • 2
  • 10
  • 27
  • 1
    If you are updating the scene graph from a background thread; see [*Concurrency in JavaFX*](https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/concurrency.htm) and this related [examle](https://stackoverflow.com/a/38031826/230513) that moves a `Circle`. – trashgod Dec 23 '21 at 17:27

0 Answers0