badpink.blogg.se

Hexagon tech
Hexagon tech











hexagon tech

Find the row and column of the box that the point falls in. private final Hexagon getSelectedHexagon(int x, int y) The solution is now as simple as finding which box a point is in, then checking to see if the point is in either of the triangles, and correcting the answer if necessary. The white portions of the hexagons show where the square and hexagonal grid share the same coordinates and the grey portions of the hexagons show where they do not. It is easy to find which of the squares a point is inside and this would give a rough approximation of which hexagon too. This image shows the top left corner of a hexagonal grid and overlaid is a blue square grid. (UPDATED: Reduced answer length, fixed bugs in code, improved quality of images) (UPDATED: Refactored code to make more understandable and more efficient) If you want to know any more information please ask,

hexagon tech hexagon tech

Although then I could just check to see if a point is included in any of the map's tile's polygons!Īt the moment the hexagons displayed are just BufferedImages. I cannot use polygons (Java), as when I get onto moving the map around on screen, and increasing it's size I'll run into problems with updating vast amounts of polygons each frame. () īut I'm not even sure where to start with Hexagons, does anyone have any experience?

hexagon tech

Int squareY = (int)(mouseY / 10) // in this case 7 Int squareX = (int)(mouseX / 10) // in this case 2 Private void getClickedSquare(MouseEvent me) I have used a square grid before, and it was relatively easy to figure out which square was selected, because pixels are also square, // Example where each square is 10 by 10 pixels: I need to be able to tell which one the mouse is over when the user clicks,Įach Hexagon is represented by an instance of a "Tile" class, however this doesn't hold any location specific data, or even a polygon, so basically the only way to tell where a particular hexagon is, is to know it's position in the 2D array. This isn't an actual image of the hex-map I am using, but uses the same size and shape hexagons I have a map made up of rows and columns of hexagons













Hexagon tech