Hello guys, I'm having some trouble understanding what's wrong with this code.
#include <SFML\Graphics.hpp>
#include <SFML\Audio\Sound.hpp>
#include <SFML\Audio\Music.hpp>
#include <iostream>
class MusicSample{
public:
void PlayMusic();
};
void MusicSample::PlayMusic(){
sf::Music mMusic;
// Open it from an audio file
if (!mMusic.openFromFile("battletoads_level1.ogg"))
{
// error...
}
// Change some parameters
mMusic.setPosition(0, 1, 10); // change its 3D position
mMusic.setPitch(2); // increase the pitch
mMusic.setVolume(50); // reduce the volume
mMusic.setLoop(true); // make it loop
// Play it
mMusic.play();
}
int main(){
sf::RenderWindow window(sf::VideoMode(300,300), "SFML");
MusicSample music;
music.PlayMusic();
window.display();
getchar();
return 0;
};
It doesn't play any music, but if we paste the same code directly into the main method it works, it also works if we make mMusic a private member.
I come from a C# background and I'm not seeing a problem with this code.
So my question is what's the problem with this code?