【发布时间】:2017-04-10 23:06:29
【问题描述】:
当我运行代码时,一切正常,只是声音没有播放。链接很好,当我放置断点并查看声音对象时,它会显示 .我在正确的地方添加了 sfml-audio-d.lib 和 sfml-audio.lib。欢迎提出任何建议。
#include <SFML/Graphics.hpp>
#include "SFML/Audio.hpp"
int main() {
sf::RenderWindow window(sf::VideoMode(600, 600), "SFML Application");
sf::SoundBuffer buffer;
buffer.loadFromFile("magicsound.mp3");
sf::Sound sound;
sound.setBuffer(buffer);
sound.play();
//
sf::Sprite background;
sf::Texture texture;
texture.loadFromFile("crash.jpg");
background.setTexture(texture);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::Resized)
{
sf::FloatRect visibleAre(0, 0, event.size.width, event.size.height);
window.setView(sf::View(visibleAre)); //background stays default size
//window can be resized without affecting background
}
}
window.clear();
window.draw(background);
window.display();
}
}
【问题讨论】:
-
首先检查loadFromFile的返回值。
-
运行程序时是否有来自控制台窗口的消息?