SFML community forums
Help => General => Topic started by: fatum on August 28, 2011, 08:12:41 am
-
Currently I'm working with this:
if (event.MouseButton.Button == 0)
{
for (int i = 0; i < blocks.size(); i++)
{
sf::Vector2f pos = blocks[i].GetPosition();
if (event.MouseButton.X >= pos.x && event.MouseButton.X < pos.x + 32 &&
event.MouseButton.Y >= pos.y && event.MouseButton.Y < pos.y + 32)
{
blocks.erase(blocks.begin() + i);
break;
}
}
}
Which works pretty well! However, whenever I alter the position of my "camera" view, of course it doesn't work anymore. Is there an offset I could apply to the condition to correct the problem?
Also, would it be better to check sprite.GetPosition().X and .Y instead of creating a Vector2f each time? Or is it not really too significant?
Thanks for any help.
-
Use RenderWindow::ConvertCoords.
Also, would it be better to check sprite.GetPosition().X and .Y instead of creating a Vector2f each time? Or is it not really too significant?
I don't think it is significant at all ;)
-
Thanks! That's exactly what I was going for. If anyone in the future is looking for a solution to a similar problem:
sf::Vector2f MousePos = App.ConvertCoords(event.MouseButton.X, event.MouseButton.Y, camera);
if (MousePos.x >= pos.x && MousePos.x < pos.x + 32 &&
MousePos.y >= pos.y && MousePos.y < pos.y + 32)