I have this strange problem where the music is loaded but nothing happens when the program is run.
This is put before my window.isOpen() loop.
Music themusic;
if(!themusic.openFromFile("ASSETS/snow.wav"))
{
MessageBox(NULL,"Not found","Error",MB_OK);
}
themusic.setVolume(100);
themusic.play();
The game updates fine.Theres no freezing going on.And I'm sure the audio file works.I have been using audio files in music and suddenly it doesn't make a sound.I'm sure my computer audio works too because sf::sound works. Either i'm doing something wrong here or something in my other code is stopping themusic. I'm certain there is no themusic.stop() anywhere in my code so i'm wondering if its some sort of problem with sfml. I did use 500 sounds. Could this effect sf:Music? I know. Why use 500 sounds? Well its actually for a sound that is played very fast so I need it.
Any ideas where the problem is?
Thanks
So strange. I cut it down to a bare minimum and I located the problem at the window declaration.
In main.h
#include <SFML\Graphics.hpp>
extern sf::RenderWindow window;
In main.cpp
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include "main.h"
#include <windows.h>
sf::RenderWindow window(sf::VideoMode(960,540),"Weather Dodger");
int main()
{
sf::Music themusic;
if(!themusic.openFromFile("ASSETS/snow.wav"))
{
MessageBox(NULL,"Not found","Error",MB_OK);
}
themusic.setVolume(100);
themusic.play();
while(window.isOpen())
{
sf::Event e;
while(window.pollEvent(e))
{
if(e.type==sf::Event::Closed)
window.close();
}
window.clear();
window.display();
}
}
With this code the music does not play.
But with window declared locally theres no problem.Any ideas why this problem occurs?
In main.cpp with window local.
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include "main.h"
#include <windows.h>
int main()
{
sf::RenderWindow window(sf::VideoMode(960,540),"Weather Dodger");
sf::Music themusic;
if(!themusic.openFromFile("ASSETS/snow.wav"))
{
MessageBox(NULL,"Not found","Error",MB_OK);
}
themusic.setVolume(100);
themusic.play();
while(window.isOpen())
{
sf::Event e;
while(window.pollEvent(e))
{
if(e.type==sf::Event::Closed)
window.close();
}
window.clear();
window.display();
}
}
Seems like a window error to me.But why? :P