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 - RumpNissen

Pages: [1]
1
Audio / Muting sounds and music
« on: February 26, 2014, 02:54:43 pm »

Well, since I got my sound manager to work. I've been trying to figure out a way to have a function that dynamically mutes all sounds and music.

See, I'm making a main menu with an options tab where you can mute the sounds and music separately. I have no idea where to start, since no one else seems to have tried doing the same thing. I guess it needs to be done through the sound manager.

Any ideas? Do I need to upload the code for the sound manager?

Any advice would be much appreciated.

2
General / sf::NonCopyable - Issue - Sound Manager
« on: February 19, 2014, 04:00:49 pm »
Greetings, I don't have much experience with SFML and I started programming with C++ just last autumn.

I used an open source sound manager for my project:
https://thunked.org/p/view/pub/ao7lc3kqg

However, the author made the mistake of setting values for the sf::Time variables in the header:

sf::Time startingPoint = sf::seconds(0);
sf::Time endPoint = sf::seconds(0);

I changed this and set the values in the .cpp instead. That's when the "sf::NonCopyable" issue showed up:

Error   2   error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'


The Sound Manager looks like this:

Header
#pragma once
#include <SFML\Audio.hpp>
#include <SFML\System.hpp>

class SoundEntity
{
public:
        sf::Time startingPoint;
        sf::Time endPoint;
        sf::Sound Sound;
        sf::SoundBuffer Buffer;
        sf::Music Music;
        void Loop();
        SoundEntity();
        void Play(bool stop);
        void Init(std::string filename);
        void Update();
};

class SoundManager
{
public:
        std::vector<SoundEntity> Sounds;
        int newSound(std::string filename, bool Looping);
        void Update();
};

CPP
#include <SFML\Audio.hpp>
#include <SFML\System.hpp>
#include <iostream>
#include "SoundManager.h"


void SoundEntity::Loop()
{
        startingPoint = sf::seconds(0);
        endPoint = sf::seconds(0);
        Sound.setPlayingOffset(startingPoint);
}

void SoundEntity::Play(bool stop = true)        // stops the sound, then starts it from the beginning of the loop, then starts it
{
        if (stop)
                Sound.stop();
        Sound.setPlayingOffset(startingPoint);
        Sound.play();
}

void SoundEntity::Init(std::string filename)
{
        //Buffer = new sf::SoundBuffer;
        Buffer.loadFromFile(filename);
        //Sound = new sf::Sound;
        Sound.setBuffer(Buffer);
        startingPoint = sf::microseconds(0);
        endPoint = Buffer.getDuration();
}

SoundEntity::SoundEntity()
{
        std::cout << "Hi\n";
}

void SoundEntity::Update()
{
        if (Sound.getPlayingOffset() >= endPoint && Sound.getLoop())
        {
                Loop();
        }
        else if (Sound.getPlayingOffset() >= endPoint)
        {
                Sound.stop();
        }
}


int SoundManager::newSound(std::string filename, bool Looping)
{
        SoundEntity newSoundEntity;
        Sounds.push_back(newSoundEntity);
        Sounds[Sounds.size() - 1].Init(filename);
        Sounds[Sounds.size() - 1].Sound.setLoop(Looping);
        return Sounds.size() - 1;
}

void SoundManager::Update()
{
        for (int i = 0; i < Sounds.size(); i++)
        {
                Sounds[i].Update();
        }

}

So what did I miss? Or is it something the original author missed?

Any help would be much appreciated

Pages: [1]