首页 > 解决方案 > SFML 在 xcode 中打开图像文件?

问题描述

我试图在 xCode 中将 .gif 文件加载到 SFML 中的纹理中,但我不知道如何打开它。

    float radius = 2.50e+11;
    CelestialBody sun(0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.9890e+30, "sun.gif", radius);
    sf::RenderWindow window(sf::VideoMode((radius/600000000.0)*2,(radius/600000000.0)*2), "test");
    while (window.isOpen())
    {

        sf::Event event;
        while (window.pollEvent(event))
        {

            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        sun.draw(window,sf::RenderStates::Default);
        window.display();
    }


    return 0;
}

当我运行此代码时,它构建得很好,并且显示了一个窗口,但是其中没有图像,当我查看控制台时,我有一个错误提示“无法加载图像”sun.gif“。原因:无法打开文件”

该文件与我的 .cpp 和 .hpp 文件位于同一文件夹中,我认为它会在那里查找图像,但现在我不确定将图像放在哪里以便 xcode 能够找到它。

标签: c++sfml

解决方案


推荐阅读