hi, i have created a game, which works except for the mouse,
basically I want the user to be able to click on a tile or location on my screen so I can add functionallity to my game.
my game world is held inside a 2d array of integers, who’s values corrispond to what 20x20 tile image will be printed to the screen.
the following shows a small part of how an image is printed to the screen, if the integer at the current place in the 2d array equals it.
for (int i = 0; i < 28; i++) {
for (int j = 0; j < 38; j++) {
Junctions.updateLights(i, j);
if(gridArray[i][j] == 1) {
// k and l == 20, so the spaces in the area are drawn 20x20 pixels apart.
g.drawImage(cacheImages.getImage("straight1.gif"), k * j, l * i ,this);
}
}
}
I’ve added mouse listener, but despite trying, my current progress is only to retrieve the current mouses position:
public void mouseClicked(MouseEvent e) {
mouseX = e.getX();
mouseY = e.getY();
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e)
}
public void mouseReleased(MouseEvent e) {
}
any help on how i could detect whether a part of the screen, preferably a place in the array or a tile has been clicked
thanks
Of course if you know and have stored exactly where pics are drawn then you don’t have to check them all, just the one with that coords (and you know how to reach it).