find closest point to mouse position
问题 I've got a grid of sprites. Now I would like to drag an image on a grid-element. Therefore I need to know which x/y of the grid-element is the closest point to the mouse-position. All the grid-elements are stored in an array. How can I achieve that? 回答1: If all you need is the x,y of the closest grid then all you have to do is. var gridX:int = Math.floor(mouseX / NumberOfColumns); var gridY:int = Math.floor(mouseY / NumberOfRows); This will convert your mouse coordinates to your grid