1
votes

I make a game in c++ using SFML library with 2d world made of tiles but when I display it, the last lines are wrong size as you can see:

as you see

The size of world is 100x100 tiles. I tried to check last tile width or displaying only first 10x10 tiles but the problem still exist so this is not problem with size of last tiles.

Here you can see: here you can see

Here is a class of Tile

class Square{
public:
    int x, y, object_type;
    sf::RectangleShape rect;
    sf::Sprite object;

    Square(sf::Color col, int b, int c){
        rect = sf::RectangleShape(sf::Vector2f(200, 200));
        rect.setFillColor(col);
        rect.setOutlineColor(sf::Color(0, 0, 0, 0));
        rect.setOutlineThickness(1);
        object_type = 0;
        x = b;
        y = c;
        rect.setPosition(790+15*x, 440+15*y);
    }
   ...
}

This is code of filling the world without changing colors of the tiles(it's only cosmetic)

    vector<vector<Square>> world;
    for(int i=0;i<100;i++){
        vector<Square> v;
        for(int j=0;j<100;j++){
            Square sq(sf::Color(255, 255, 255), j, i);
            v.push_back(sq);
        }
        world.push_back(v);
    }

And this is how am I displaying it

window.clear();
for(int i=0;i<world.size();i++) for(int j=0;j<world.at(i).size();j++){
    window.draw(world.at(i).at(j).rect);
    if(world.at(i).at(j).object_type) window.draw(world.at(i).at(j).object);
}
window.display();
1
We can not see the whole code. If you can please provide a minimal compilable example. Chances are, that the error is somewhere in the code you did not disclose. - Taron

1 Answers

1
votes

XDDDDDDDD I cannot belive how terrible idiot I am

rect = sf::RectangleShape(sf::Vector2f(200, 200));
rect.setPosition(790+15*x, 440+15*y);

I just made wrond position details 15 != 200 I will not delete this question even if it's shaming for my programming(and brain-using) skills because someone can has similar problem