无法加载图片“stone.png”。原因:无法打开文件(SFML)

问题描述 投票:0回答:0

我在 Visual Studio 上使用 SFML,并在资源文件中放置了一个名为“stone.png”的文件。

#include <SFML/Graphics.hpp>

int WIDTH = 500;
int HEIGHT = 500;

int main() {


    sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "SFML Game");
    window.setFramerateLimit(60);
    sf::Event e;

    sf::Texture t1, t2, t3, t4;
    t1.loadFromFile("stone.png");

    sf::Sprite sBackground(t1);
    

    while (window.isOpen()) {
        while (window.pollEvent(e)) {
            if (e.type == sf::Event::Closed) {
                window.close();
            }
        }

        window.clear();
        window.draw(sBackground);
        
    }

    return 0;
}

当我运行此代码时,出现上述错误。

c++ image sfml
© www.soinside.com 2019 - 2024. All rights reserved.