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/ao7lc3kqgHowever, 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