I'm trying to create a PacMan game, but I'm trying to use platform.runLater() to implement multithreading and the GUI's not updating, even though I've checked that the code itself is running. Here's the pertinent code:
This is the block of code that starts the Platform.runLater() thread.
private void startTimer() {
this.timer = new java.util.Timer();
TimerTask timerTask = new TimerTask() {
public void run() {
Platform.runLater(new Runnable() {
public void run() {
update();
}
});
}
};
long frameTimeInMilliseconds = (long)(1000.0 / FRAMES_PER_SECOND);
this.timer.schedule(timerTask, 0, frameTimeInMilliseconds);
}
private void update() {
view.update(this.modelo);
}
And this is the block of code that it is running.
public void update(Model gc) {
updateMap(gc);
}
//Sets the image on the already initialized imageviews (not updating gui for some reason)
private void updateMap(Model gc) {
for(int i = 0; i < rowCount; i++) {
for(int j = 0; j < columnCount; j++) {
char valor = gc.getCelulas(i, j);
if(valor == 'E' || valor == 'W') {
visaoMapa[i][j].setImage(imgsMapaVazio[i][j]);
}
else {
if(valor == 'S')
visaoMapa[i][j].setImage(imgsMapaCheio[i][j]);
}
}
}
}
Update #1 Following James_D's recommendation, I tried changing the startTimer method into this:
private void startTimer() {
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
update();
}
};
timer.start();
}
However, the issue still persists.