Hi,
In my MouseInputHandler I’m checking each mouse movement which tile is getting hovered.
Now I was wondering… Is this a good way to handle this? (I’m talking about the threading)
@Override
public void mouseMoved(MouseEvent e) {
mousePosition = e.getPoint();
Thread t = new Thread() {
@Override
public void run() {
switch (Core.getGameState()) {
case INGAME: // Only perform when we're ingame so we know for sure that there are tiles..
if (activeTile != null) {
/**
* Get active tile, and unset if mouse is out of it
*/
if (!activeTile.getEdges().contains(mousePosition)) {
activeTile.setBorderColor(activeTile.getDarkPixelBorderColor());
activeTile = null;
}
} else {
/**
* Loop trough tiles Cecks if mouse is hovered If
* hovered, border goes green. If not, border goes
* black.
*/
for (int x = 0; x < Core.getTiles().length; x++) {
for (int y = 0; y < Core.getTiles()[x].length; y++) {
Tile t = Core.getTiles()[x][y];
if (t.getEdges().contains(mousePosition)) {
t.setBorderColor(t.getLightPixelBorderColor());
} else {
t.setBorderColor(t.getDarkPixelBorderColor());
}
}
}
}
break;
}
}
};
t.start();
}
Thanks in advance!