A better way to do it, like kappa suggested, is to use math. If you are using a grid, and saving the tiles in a 2d array, try this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| int mouse_x; int mouse_y; Tile mouseTile; public void mouseMoved(MouseEvent e) { int xx = e.getX(); int yy = e.getY(); mouse_x = xx-(xx%gridSize)/16; mouse_y = yy-(yy%gridSize)/16;
if(mouseTile != null) {mouseTile.setSelected(false);} if() { mouseTile = Core.getTiles()[x][y]; } } |
There are several things that need to be changed, but these are the basics.