First I'm still newish to sfml. I have been tinkering with it on/off for a while now and I've been using only really basic items. i.e. loading texture, drawing sprites, changing colour of sprites. I've also setup a nice wee GUI using the tgui libs.
Anyway, I have a basic game working now but I want to start doing more advance stuff with the sprites. The game at it's core has a real-life map of Europe, split into individual regions. Each png are all of the same size, say 1218 X 730. The background is transparent and each image has each a shaded area for that region, drawn in the proper position. i.e. Italy is drawn where italy should be, etc, etc
The reason I did it this way was because it allows me to set the sprite position as 0,0 and the regions of europe all line up perfectly. When I tried having each region image as a small image, it was a nightmare to try to align up each region correctly.
Anyway, what I want to do now is to have army sprites on the map, but they should only go on the land areas of the region map. So I need a way to detect whether a sprite's position is within a shaded area and indeed which region it is located. As the region areas are all irregular, then defining via hard-coded values would seem to be quite a difficult and likely involve overlap.
Also I cannot simply check the bounding box i.e. something like below, as I assume the bounding box will the same for all regions i.e. 1218 * 730. Right?
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
// transform the mouse position from window coordinates to world coordinates
sf::Vector2f mouse = window.mapPixelToCoords(sf::Mouse::getPosition(window));
// retrieve the bounding box of the sprite
sf::FloatRect bounds = sprite.getGlobalBounds();
// hit test
if (bounds.contains(mouse))
{
// mouse is on sprite!
}
}
So I am wondering if there is any dynamic way to go about checking whether a mouse or another sprite is located on a shaded part of a texture? Is this possible with SFML and if so how (at a high-level - not looking for someone to write the code) ?