Hello all. I'm wrapping sf::SoundBuffer and sf::Sound classes in a class named SoundObject. It is followed like this:
SoundObject.h
#ifndef SOUNDOBJECT_H
#define SOUNDOBJECT_H
#include <string>
#include <SFML/Audio.hpp>
class SoundObject {
public:
SoundObject();
bool Create(std::string filename);
void Play();
private:
sf::Sound soundInstance;
sf::SoundBuffer soundBuffer;
};
#endif
SoundObject.cpp
#include "SoundObject.h"
#include <string>
#include "../GameProperties/GameProperties.h"
SoundObject::SoundObject() {
}
bool SoundObject::Create(std::string filename) {
if (!soundBuffer.loadFromFile(filename)) {
return false;
}
soundInstance.setBuffer(soundBuffer);
return true;
}
void SoundObject::Play() {
soundInstance.setVolume(GameProperties::GetSFXVolume());
soundInstance.play();
}
And I'm calling these functions in a class like this:
if (!changeSound.Create("Sounds/System/sound_change.ogg")) {
return false;
}
if (!selectSound.Create("Sounds/System/sound_select.ogg")) {
return false;
}
changeSound and selectSound is member of a class.
But it gives access violation error. When I try to play the sounds in the main function, it doesn't give error. I don't get it. Can you help me?
Thanks.