Assuming square cells, 1-based row/col indexing, and truncating integer division:
col = mouse.X / cellSize + 1;
row = mouse.Y / cellSize + 1;
Question
I need to find what column and row the mouse location is in. To simplify this question, lets only find the column. I will write in pseudocode.
I have a map (a grid of rows and columns, made up by square cells) with a pixel width. I have a cell size which makes up each columns pixel width.
eg map.width / cell size = map.NumberOfColumns.
From this we can get what column the mouse is on.
Eg if ( mouse.X > cellSize ) {col is definitely > 1} (i have not used zero indexing in this example).
So if anyone here loves maths, i would very much appreciate some help. Thanks.
La solution
Assuming square cells, 1-based row/col indexing, and truncating integer division:
col = mouse.X / cellSize + 1;
row = mouse.Y / cellSize + 1;