我试图从文本文件加载图块地图,但是当我在屏幕上渲染它时,它会向侧面移动,因此左边的块会移到屏幕的右边,右边的块会移到屏幕的右边。剩下。我在做错什么,请帮忙。
void blocks::genBlocks(blocks getBlocks) {
ifstream mapFile("Data/block_map.txt");
if (mapFile.is_open()) {
while (!mapFile.eof()) {
blockData = 0;
mapFile >> blockData;
if (mapFile.peek() == '\n') {
loadCounterY++;
loadCounterX = 1;
}
else {
loadCounterX++;
}
if (blockData == 1) {
blockRect.setPosition(loadCounterX * 110, loadCounterY * 40);
blocksVec.push_back(getBlocks);
}
}
}
}
void blocks::renderBlocks(RenderTarget &window) {
for (int i = 0; i < blocksVec.size(); i++) {
window.draw(blocksVec[i].blockRect);
}
}
它应该是这样的:(1表示画一些东西,0表示什么都不画)
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 1
但结果看起来像这样:
1 0 0 0 0 0
1 0 0 0 0 0
1 0 0 0 0 0
1 0 0 0 0 0
1 0 0 0 0 0
1 0 0 0 0 0