SFML 웹사이트의 그래픽 스프라이트 튜토리얼에서 직접 가져온 것입니다.
"The loadFromFile function sometimes fails with no obvious reason. First, check the error message printed by SFML in the
standard output (check the console). If the message is unable to open file, make sure that the working directory (which is the
directory any file path will be interpreted relatively to) is what you think it is: when you run the application from the explorer, the
working directory is the executable folder, but when you launch your program from your IDE (Visual Studio, Code::Blocks, ...) the
working directory is sometimes set to the project directory instead. This can generally be changed easily in the project settings."
따라서 먼저 이미지 이름이 올바른지 확인하고 두 번째로 이미지가 올바른 폴더에 있는지 확인하세요.작업 디렉토리에 있습니다.
또한 빈 스프라이트를 반환하는 대신 텍스처가 로드되지 않으면 콘솔에 오류를 보고한 다음 예외를 발생시킬 수 있습니다.이렇게 하면 스프라이트가 올바르게 로드되지 않는다는 메시지가 표시되며 프로그램은 예외를 처리해야 하며 그렇지 않으면 프로그램이 종료됩니다.이런 식으로 게임에서 스프라이트는 의도적이지 않는 한 흰색 질감이 없어야합니다.
이 같은:
sf::Texture texture;
if (!texture.loadFromFile("image.png"))
{
throw std::runtime_error("Could not load image.png");
}