Reputation: 31
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:
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 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();
Upvotes: 1
Views: 218
Reputation: 31
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
Upvotes: 2