简体   繁体   English

SFML 没有声音播放存储在 ResourceHolder 中的声音缓冲区

[英]SFML no sound playing with soundbuffers stored in ResourceHolder

i'm currently working on a small game with sfml.我目前正在使用 sfml 开发一个小游戏。

For resource loading and holding i'm using the ResourceHolder described in the SFML Game Development Book: SFML ResourceHolder Basically the resources are stored as unique_ptr in a map.对于资源加载和保持,我正在使用 SFML 游戏开发手册中描述的 ResourceHolder: SFML ResourceHolder基本上,资源在地图中存储为 unique_ptr。

Inside a SoundManager class i'm loading different sounds to this ResourceHolder.在 SoundManager 类中,我正在向这个 ResourceHolder 加载不同的声音。 This SoundManager has a playSound function when i want to play a sound.当我想播放声音时,此 SoundManager 具有 playSound 功能。

void SoundManager::playSound(SoundType soundToPlay) {
    auto buffer = sounds.get(soundToPlay);
    auto sound = sf::Sound(buffer);
    sound.play();
}

but i don't hear any sounds.但我听不到任何声音。 Do i have to store different sound objects for every sound in a map?我是否必须为地图中的每个声音存储不同的声音对象? I also tried to use a sf::Sound object as a class member, but this also didn't worked.我还尝试使用 sf::Sound 对象作为类成员,但这也不起作用。

Using this ResourceHolder my textures are loaded correctly.使用这个 ResourceHolder 我的纹理被正确加载。

Thank you for you help谢谢你的帮助

我能够在 sfml-dev 论坛中通过一些输入链接描述来解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM