【发布时间】:2018-01-18 18:22:56
【问题描述】:
我正在尝试使用 window.draw() 函数将来自文本文件的二维字符数组打印到渲染窗口中。然而,一切似乎都工作得很好,除了在打印它时恰好跳过一个字符。 例如,如果我有一行 15 个字符,它只会打印 8 个,但是当我在终端上打印它时,它打印得非常好,我根本不知道它为什么会这样,尝试了几件事,比如更改文本文件本身,或更改大小。似乎没有什么对我有用。非常感谢任何想法或帮助。
这里是部分代码:
void Level::printgrid(int level)
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Game On");
sf::Font MyFont;
if (!MyFont.loadFromFile("tnr.ttf"))
{
// Error...
}
ifstream my_file("nn.txt"); //text that i will be reading from
char number;
int i = 0; //to help loop
int j = 0;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
else
{
window.clear();
while (i<row) // ive tried 2 for loops that didnt work cause
{ // it kept re-entering those loops
while (j<col)
{
my_file.get(grid[i][j]); //getting the chars one by one
cout << grid[i][j]; // printing them on terminal
//so i can check its correct
//changing to text that is drawable to print in window
sf::Text text(grid[i][j], MyFont, 30);
text.setPosition(0 + (30 * i), 0 + (30 * j));
// drawing it in window
window.draw(text);
window.display();
j++;
}
my_file.get(number);
cout << endl;
i++;
j = 0;
}
}
}
}
}
【问题讨论】:
标签: c++ visual-studio sfml