Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - sima

Pages: [1]
1
Thank you!
I didn't see that I returned a copy in the ResourceHolder instead of the reference.
I could build it now with unique_ptr.

2
Thanks for your reply.
I tried to use a private class member sf::Sound sound but this also didn't worked.
Currently i have the following structure:
In the class header file:
class SoundManager {
    private:

        res::ResourceHolder<sf::SoundBuffer, SoundType> soundBuffers;
        sf::Music music;
        sf::Sound sound;

        std::map<SoundType, std::string> soundFiles = {
                {SoundType::JUMP,   "../resources/sounds/jump.ogg"},
                [...]
        };


then in a load function all of my sounds are loaded into the soundBuffers:
bool SoundManager::load() {

        for (auto[k, v]: soundFiles) {
            try {
                soundBuffers.load(k, v);

            } catch (std::runtime_error &e) {
                return false;
            }
        }
        return true;
    }


    void SoundManager::playSound(SoundType soundToPlay) {
        auto buffer = soundBuffers.get(soundToPlay);
        auto soundOption = soundOptions[soundToPlay];
        sound.setLoop(soundOption.loop);
        sound.setVolume(soundOption.volume);

        std::cout << "Play sound";
        sound.play();

    }


And i checked everything, my load function is called and the playSound function is called.

3
Audio / SFML no sound playing with soundbuffers stored in ResourceHolder
« on: November 06, 2021, 03:18:06 pm »
Hi,

i'm currently working on a small game with sfml.

For resource loading and holding i'm using the ResourceHolder described in the SFML Game
Development Book: https://github.com/SFML/SFML-Game-Development-Book/blob/master/02_Resources/Include/Book/ResourceHolder.hpp

Inside a SoundManager class i'm loading different sounds to this ResourceHolder. This SoundManager has a playSound function when i want to play a sound.

    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.

Using this ResourceHolder my textures are loaded correctly.

Thank you for you help

Pages: [1]