Help => Audio => Topic started by: aNewHobby on April 14, 2012, 09:18:01 am
Title: Strange Music Behaviour (using demo code)
Post by: aNewHobby on April 14, 2012, 09:18:01 am
Hi there,
I have been playing around and found a strange problem when i tried to use the Music.Play(); in a practical situation.. after much confusion I found a strange problem and it happens even in he demo code in the tutorial section .. so I guess I am just not using it correctly?
I recorded the problem here do you can have a look http://screencast.com/t/SLYFFtSfke
Basically this is the exact code form the tutorial... I have jus tremoved somne of it.. but I am not sure why this would make a difference...
The plan is to add the audio to this class and use it to play things and stuff. I addedthe music to the constructor so it start as I declare the object I'll also add a few effect sounds that will always be live.
Anyway.. am i doing this all wrong? Why woudl i need a cin.get after the Music.Play() to make the sound come out?
Title: Re: Strange Music Behaviour (using demo code)
Post by: Laurent on April 14, 2012, 09:27:37 am
The sf::Music instance is local to the constructor, therefore it is destroyed when the constructor returns. And a destroyed music cannot be heard ;)
By the way,
typedefclass xxx { } xxx;
... is a C thing, you don't need it in C++.
class xxx { };
Title: Re: Strange Music Behaviour (using demo code)
Post by: aNewHobby on April 14, 2012, 09:31:02 am
oh right.. . :-\
I feel sily now.. yeah of course. .I just moved "sf::Music Music;" into the class definitions and it now works..
class MySounds{ sf::Music Music; public: MySounds(); void music(); };