Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Strange Music Behaviour (using demo code)  (Read 2795 times)

0 Members and 1 Guest are viewing this topic.

aNewHobby

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • Live 4 Ever Or Die Trying
Strange Music Behaviour (using demo code)
« 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...

Here is my

MySounds.cpp - http://ideone.com/36yr1
MySounds.h - http://ideone.com/3HZOI

I call the class in main as "MySounds Sound;"

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?
Twitter: @Jyinkies
My Own Little Spot on the Net: - Live4everOrDieTrying.info (Blog)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Strange Music Behaviour (using demo code)
« Reply #1 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,
typedef class xxx
{
} xxx;
... is a C thing, you don't need it in C++.
class xxx
{
};
Laurent Gomila - SFML developer

aNewHobby

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • Live 4 Ever Or Die Trying
Re: Strange Music Behaviour (using demo code)
« Reply #2 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();
};
Twitter: @Jyinkies
My Own Little Spot on the Net: - Live4everOrDieTrying.info (Blog)

 

anything