I have a map made up of rows and columns of hexagons
This isn\'t an actual image of the hex-map I am using,
This is an addendum to SebastianTroy's answer. I would leave it as a comment but I don't enough reputation yet.
If you want to implement an axial coordinate system as described here: http://www.redblobgames.com/grids/hexagons/
You can make a slight modification to the code.
Instead of
// Is the row an odd number?
if (rowIsOdd)// Yes: Offset x to match the indent of the row
column = (int) ((x - halfWidth) / gridWidth);
else// No: Calculate normally
column = (int) (x / gridWidth);
use this
float columnOffset = row * halfWidth;
column = (int)(x + columnOffset)/gridWidth; //switch + to - to align the grid the other way
This will make the coordinate (0, 2) be on the same diagonal column as (0, 0) and (0, 1) instead of being directly below (0, 0).
I dont know if it's going to help anyone but i have come up with a much simpler solution. When i create my Hexagon im just giving them a middle point and by finding the closest middle point with the mouse coordonate i can find wich one im on !