I have an sf::VertexArray of sf::Quads. As you can see by my code below, I loop through, then display them in a grid that takes up the entire window. Based on this code that determines where each tile goes into the VertexArray (0,4,8,12, etc)...
(x + y * numOfHorizTiles) * 4;
How can I determine which tile was clicked on with the x/y coordinates of a mouse click? Getting the mouse coordinates isn't a problem. The trouble is when I try to determine which tile it translates to. "x" in this sense means the number of tiles across, but the mouse click will be in pixels not tiles. So an x axis coordinate of 15 pixels could be on tile two.
for(int x = 0; x < numOfHorizTiles; ++x)
{
for(int y = 0; y < numOfVertTiles; ++y)
{
sf::Vertex* quad = &tileVertices[(x + y * numOfHorizTiles) * 4];
quad[0].position = sf::Vector2f(x * TILE_SIZE, y * TILE_SIZE);
// etc...
}
}
Thanks for any help.