加载纹理。
什么有效:I使用
std::filesystem::current_path()
C:/Users/Ola/Desktop/Studia/c++/Szachy/x64/Debug
void ChessGame::loadTextures() {
if (!boardTexture.loadFromFile("images/board.png")) {
std::cerr << "Failed to load board texture (images/board.png)" << std::endl;
}
if (!pieceTexture.loadFromFile("images/figures.png")) {
std::cerr << "Failed to load piece textures (images/figures.png)" << std::endl;
}
boardSprite.setTexture(boardTexture);
for (int i = 0; i < 32; i++) {
pieces[i].setTexture(pieceTexture);
}
}
folder结构:
x64
└── Debug
├── Szachy.exe
├── images
│ ├── board.png
│ └── figures.png
控制台中的eRROR消息:
Failed to load image "". Reason: Unable to open file
Failed to load board texture
Failed to load piece textures
可能导致这个问题,我该如何解决?
当您最终将一个空字符串或随机字符作为错误消息中的路径时,通常是运行时兼容性损坏的指示。大多数情况下,人们以调试模式链接SFML发布库,或以发行模式链接debug库,因此最终以其应用程序代码和SFML之间的不同,不兼容的运行时间。
确保您仅在调试模式配置中将库文件与-d
后缀链接,而在发行模式下没有后缀。
注:如果您使用静态库,则后缀为debug,并且with worizeworree