How do you compare Vectors in map for sfml?

Viewed 78

I'm trying to create an array of objects I'm calling tiles for a game. I'm using the following map to track their locations using Vector2i objects and and tile objects:

std::map<sf::Vector2i, Tile, compareVector2i> allTiles;

I read online that since the Vector2i object does not have a way to compare two of them, I have to create it myself and add it to the map, so I created the following struct and function to compare them

struct compareVector2i {
    bool operator()(const sf::Vector2i& a, const sf::Vector2i& b) const {
        return a.x < b.x || a.y < b.y;
    }
};

but it's not printing the array right when I loop through the tiles like this:

    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){.   //array of 100x100

        }
    }

I noticed that when I change the comparing function, the printing of the tiles changes too. I didn't think this would be a problem because since every vector is different, when I access a specific one I should get the assigned tile. I'm not a pro at maps, so my guess is the comparing function is used to find values from keys?

Does anybody know of way to fix this?

0 Answers
Related