Easy!
GridXPosition := Mouse.X div GridCellWidth;
And if your map is bigger than what you can render on the screen you have to take into acount your viewing position. So if your viewing position on X axis is at coordinates 145 the forumla would look like this:
GridXPosition := (Mouse.X + ViewpoirtX) div GridCellWidth;
Once you have grid position you can simply multiply it by grid size like this.
SelectorSprite.X := GridXPosition * GridCellWidth;
And if your map is larger than the screen
SelectorSprite.X := (GridXPosition * GridCellWidth) - ViewportX;
Bookmarks