嗨,我有一个用于映射的类,它正在绘制到屏幕上,但它只在窗口左侧垂直向下绘制。我可以弄清楚我哪里出错了。任何帮助将非常感激。很确定这与我在绘图函数中的 for 循环有关。
void Map::Initialise(const char *filename)
{
std::ifstream openfile(filename);
std::string line;
std::vector <int> tempvector;
while(!openfile.eof())
{
std::getline(openfile, line);
for(int i =0; i < line.length(); i++)
{
if(line[i] != ' ') // if the value is not a space
{
char value[1] = {line[i]}; // store the character into the line variable
tempvector.push_back(atoi(value)); // then push back the value stored in value into the temp vector
}
mapVector.push_back(tempvector); // push back the value of the temp vector into the map vector
tempvector.clear(); // clear the temp vector readt for the next value
}
}
}
void Map::DrawMap(sf::RenderWindow &Window)
{
sf::Shape rect = sf::Shape::Rectangle(0, 0, BLOCKSIZE, BLOCKSIZE, sf::Color(255, 255, 255, 255));
sf::Color rectCol;
sf::Sprite sprite;
for(int i = 0; i < mapVector.size(); i++)
{
for(int j = 0; j < mapVector[i].size(); j++)
{
if(mapVector[i][j] == 0)
rectCol = sf::Color(44, 117, 255);
else if (mapVector[i][j] == 1)
rectCol = sf::Color(255, 100, 17);
rect.SetPosition(j * BLOCKSIZE, i * BLOCKSIZE);
rect.SetColor(rectCol);
Window.Draw(rect);
}
}
}