I have a really strange behavior in one of my methods.
boolean checkMapObjects(Vector2 enemypos, Vector2 playerpos) {
MapLayers layers = map.getLayers();
for (int i = 0; i < layers.getCount(); i++) {
MapLayer layer = layers.get(i);
if (layer.getName().contains("collision")) {
for (MapObject obj : layer.getObjects()) {
Rectangle rect = ((RectangleMapObject) obj).getRectangle();
float[] vects = {rect.getX(), rect.getY(), rect.getX(), rect.getY() + rect.height,
rect.getX() + rect.width, rect.getY() + rect.height, rect.getX() + rect.width, rect.getY()};
if (Intersector.intersectLinePolygon(enemypos, playerpos, new Polygon(vects)))
return true;
}
}
}
return false;
}
First: the function also uses the last return statement, but thats not the main-issue. What really surpises me is that function inverts the returned value. If I call it from an other function like this
boolean wtf=checkMapObjects(enemypos, playerpos);
wtf
will always be the inverse value of what SHOULD be returned.
can anyone tell me why?
Just for testing I tried returning true instead of false, but again the value is inverted
Found it, the enemy collided with a wall... because I needed to use Segement not line^^