1
\$\begingroup\$

I have my isometric world represented by isometric tiles. If I were to allow the player to place buildings on any of the tiles how would I get this funcitonality to work?

I was thinking if I could add a MouseListener to the images?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You have mentioned you have a mouse listener and an image object but have not told us what environment this is done in so I do not think we can give you an answer you want. \$\endgroup\$
    – James
    Commented Dec 4, 2011 at 23:37
  • \$\begingroup\$ Oh my mistake, it's being made in Java. I'm using the Diamond approach. \$\endgroup\$ Commented Dec 4, 2011 at 23:47

1 Answer 1

5
\$\begingroup\$

I would highly recommend not using the MouseListener on the images for one main reason: The graphics should only be a visual representation of what's happening in the game. Using the graphics to control the game creates high coupling between the graphics and the game, which will make it hard to modify or improve later down the road.

I would recommend using math to convert the mouse position to a game position like this article describes: http://www.tonypa.pri.ee/tbw/tut18.html

\$\endgroup\$
4
  • \$\begingroup\$ I see, I've read about other implementations involving using the matrix inverse to inverse mouse co-ordinates which output the tile's co-ordinates but I'm not entirely sure if I understood the article or not, am I right in this assumption? \$\endgroup\$ Commented Dec 5, 2011 at 18:01
  • \$\begingroup\$ @user1048606, I'm not very familiar with Matrices myself, but I'm sure there are ways that you can use them to convert from screen-space (the mouse) to game-space. Do a few google searches, and you will surely find an article that describes how to do this using Matrices, it's not an uncommon procedure. To be clear, you can either use matrices, or you can use plain old math, whichever you are more comfortable with. Using a matrix will probably be faster, but if you are unfamiliar with them, the processing speed isn't worth the headache imo. \$\endgroup\$ Commented Dec 5, 2011 at 18:20
  • \$\begingroup\$ I'm able to get the tile positions now but I'm still unable to highlight tiles as my cursor goes over them and I'm unable to place building on my tiles. \$\endgroup\$ Commented Dec 6, 2011 at 1:39
  • \$\begingroup\$ @user1048606, you should make a new question for the new issues. Sorry, I can't help any more. \$\endgroup\$ Commented Dec 6, 2011 at 17:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .