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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Anis

Pages: [1]
1
Audio / Re: My Sonnd doesn't play
« on: July 15, 2024, 12:48:24 am »
I solved the problem using another class and i use it with callBack and it work, thank you for your suggestions

2
Audio / My Sonnd doesn't play
« on: July 12, 2024, 10:02:23 pm »
Hi everyone, i have a proplem, my sound doesn't play in my program, i have the message "song played" but the program still doesn't play the song, i already checked my own sound devices, and the soundBuffer and the Sound object are variables of the class, so i don't think that is a variable scope problem. so here is the code, if someone have an idea.


class TBIbutton
        {
               
        public:
                TBIbutton(std::string txtBTN, uint16_t numberTypeAnimation = uint16_t(4), std::shared_ptr<sf::SoundBuffer> bufferSoundBtnHovered = nullptr, std::shared_ptr<sf::Sound> soundBtnHovered = nullptr, std::shared_ptr<sf::SoundBuffer> bufferSoundBtnClicked = nullptr, std::shared_ptr<sf::Sound> soundBtnClicked = nullptr);
                virtual ~TBIbutton();
               
        private:
               
                // sounds
                sf::SoundBuffer bufferSoundWhenBTNHovered;
                sf::Sound soundWhenBTNHovered;
                sf::SoundBuffer bufferSoundWhenBTNClicked;
                sf::Sound soundWhenBTNClicked;

                bool ifPlaySoundWhenBtnHovered;
                bool ifPlaySoundWhenBtnClicked;
                bool ifAlreadyPlayedSoundBTNHovered;
                bool ifAlreadyPlayedSoundBTNClicked;

                bool ifBTNcurrentlyClick;

        };

 
constructor of TBIbutton:
TBIbutton::TBIbutton(std::string txtBTN, uint16_t numberTypeAnimation, std::shared_ptr<sf::SoundBuffer> bufferSoundBtnHovered, std::shared_ptr<sf::Sound> soundBtnHovered, std::shared_ptr<sf::SoundBuffer> bufferSoundBtnClicked, std::shared_ptr<sf::Sound> soundBtnClicked)
{
   

   // sound
   this->ifPlaySoundWhenBtnHovered = true;
   this->ifPlaySoundWhenBtnClicked = true;
   this->ifAlreadyPlayedSoundBTNHovered = false;
   this->ifAlreadyPlayedSoundBTNClicked = false;
   this->ifBTNcurrentlyClick = false;

   if (bufferSoundBtnHovered != nullptr)
   {
      bufferSoundWhenBTNHovered = *bufferSoundBtnHovered;
      soundWhenBTNHovered = *soundBtnHovered;
   }
   else
   {
      this->ifPlaySoundWhenBtnHovered = false;
   }

   if (bufferSoundBtnClicked != nullptr)
   {
      bufferSoundWhenBTNClicked = *bufferSoundBtnClicked;
      soundWhenBTNClicked = *soundBtnClicked;
   }
   else
   {
      this->ifPlaySoundWhenBtnClicked = false;
   }
}


 
void TBIbutton::draw(sf::RenderWindow& window, std::chrono::duration<double>& clock, sf::Event& event, sf::Vector2i mousePos, ValuesAnimation& values, bool& ifAnimationOpacity)
{
                if (ifBtnClick<TBIbutton>(*this, event, mousePos))
                {
                        if (this->ifAlreadyPlayedSoundBTNHovered == false && this->ifPlaySoundWhenBtnHovered == true && this->ifBTNcurrentlyClick == false)
                        {
                                std::cout << "song PLAYED !!!" << std::endl;
                                soundWhenBTNHovered.play();
                                this->ifAlreadyPlayedSoundBTNHovered = true;   
                        }
                        ifBTNcurrentlyClick = true;
                }
               
                        }
                }
                if (!ifBtnClick<TBIbutton>(*this, event, mousePos) && values.IfAnimationColorFinish == true)
                {
       
                {
                        if (this->ifBTNcurrentlyClick == true) // if we don&#39;t click on the btn
                        {
                                this->ifBTNcurrentlyClick = false;
                                this->ifAlreadyPlayedSoundBTNHovered = false;
                                this->ifAlreadyPlayedSoundBTNClicked = false;
                        }
                }
       
}

 

and here is when we make an instance of this class


// sound btn
                                                        std::shared_ptr<sf::SoundBuffer> soundbufferBtn = std::make_shared<sf::SoundBuffer>();
                                                        std::shared_ptr<sf::Sound> soundBtn = std::make_shared<sf::Sound>();
                                                        if (!soundbufferBtn->loadFromFile("Resources/sounds/SelectBtn.wav"))
                                                        {
                                                                std::cout << "erreur load sound" << std::endl;
                                                        }
                                                        soundBtn->setBuffer(*soundbufferBtn);
                                                        soundBtn->setVolume(100);

btn_buyOneOrSeveralsShares.push_back(std::make_unique<TheBestInvestorInterface::TBIbutton>("Buy company shares", size_t(4), soundbufferBtn, soundBtn));

 

Pages: [1]
anything