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?

  • 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
    Dec 4 '11 at 23:37
  • \$\begingroup\$ Oh my mistake, it's being made in Java. I'm using the Diamond approach. \$\endgroup\$ Dec 4 '11 at 23:47

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

  • \$\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\$ Dec 5 '11 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\$ Dec 5 '11 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\$ Dec 6 '11 at 1:39
  • \$\begingroup\$ @user1048606, you should make a new question for the new issues. Sorry, I can't help any more. \$\endgroup\$ Dec 6 '11 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.