When creating a row of sf::ConvexShapes from data in a .txt file, there is a slight gap between each shape. If I create each shape with the same data inside the code itself, then there is no gap formed.
std::ifstream fin;
std::string str("levels/level" + std::to_string(levelNumber) + ".txt");
fin.open(str);
int yCounter = 0; //incr whenever file reads /n
if(fin.good()){
while(!fin.eof()){
std::string line;
//this happens once per line, so whenever the while statement breaks, that means incr yCounter
while(std::getline(fin, line)){
int xCounter = 0; //incr for each char, reset per line
for(int i = 0; i < line.length(); i++){
if(line[i] == 'w'){
AddWall(xCounter, yCounter, tileSize);
}
xCounter++;
}
yCounter++;
}
}
}
void AddWall(int posX, int posY, int tileSize){
objects.push_back(new Platform(posX, posY, tileSize));
}
Platform::Platform(int posX, int posY, int tileSize){
shape.setPointCount(4);
shape.setPoint(0, sf::Vector2f(posX, posY));
shape.setPoint(1, sf::Vector2f(posX, posY + tileSize));
shape.setPoint(2, sf::Vector2f(posX + tileSize, posY + tileSize));
shape.setPoint(3, sf::Vector2f(posX + tileSize, posY));
shape.setFillColor(sf::Color::White);
shape.setPosition(posX * tileSize, posY * tileSize);
}
A screenshot of the gap is included. I know I can just add outlines to the shapes to solve this, but why is the problem happening in the first place?