First of all, thank you for this great map loader! I'm using it in my game project and it works really well. Except, I have a problem now that I couldn't solve.
If I understand correctly, the Intersects method in MapObject class is supposed to return true when the two MapObjects have overlapping area, false otherwise. At least that is how I expected to use it. However, it gives random results for me.
The code I wrote looks like this:
void Player::interact()
{
std::cerr<<"E"<<std::endl;
//Determines the new position of the interactBox (a rectangular MapObject)
sf::Vector2f pos;
pos.x = getPosition().x + direction.x*10.f -inbox_width/2;
pos.y = getPosition().y + GetAnSprite().getLocalBounds().height/2 + direction.y*10.f -inbox_height/2;
//Sets position of the box
interactBox->SetPosition(pos);
//finds the right layer and checks for objects
std::vector<tmx::MapLayer> layers = Game::getMapLoader().GetLayers();
for(auto& layer : layers)
{
if(layer.type == tmx::ObjectGroup && layer.name == "interaction")
{
for(auto& obj : layer.objects)
{
if(interactBox->Intersects(obj))
{
std::cerr<<obj.GetName()<<std::endl;
break;
}
}
break;
}
}
}
This method is called everytime I press "E".
I recorded an example of how it behaves:
http://gfycat.com/PerkyIncredibleHeron Here the red box is the DebugShape of interactBox, the gray boxes are the objects in the "interactions" layer of the map. The first sign I am trying to interact is named "sign1" and the gray box at the top that I can interact without even touching is named "rect1".
It seems I have done something wrong and I just can't figure out why! I have poor programming skills despite coding for many years so it would be very nice if whoever understands my problem explains it to me in a simple way. Thank you in advance!