首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在SFML应用程序中是否有打开或关闭一般声音的方法?

在SFML应用程序中是否有打开或关闭一般声音的方法?
EN

Stack Overflow用户
提问于 2022-12-04 20:20:19
回答 1查看 22关注 0票数 1

我想在main.cpp中做一个按钮,按下一般声音会打开或关闭的按钮,但是我的声音分散在每个.h和.cpp文件上。

我创建了按钮本身,但到目前为止它并不包含任何内容。

在阅读了SFML中有关声音的文档之后,我找不到想要的函数,等等。

如果有这样的功能,我会很高兴的。

例如: GameState.h

代码语言:javascript
复制
class GameState :
    public State
{
private:
    sf::SoundBuffer soundBufferMiss;
    sf::SoundBuffer soundBufferCrash;
    sf::SoundBuffer soundBufferStartGame;
    sf::SoundBuffer soundBufferWin;
    sf::SoundBuffer soundBufferLose;

    sf::Sound soundMiss;
    sf::Sound soundCrash;
    sf::Sound soundStartGame;
    sf::Sound soundWin;
    sf::Sound soundLose;

    sf::Text textAboutPlayer;
    sf::Text textAboutEnemy;
    sf::Text textInfo;

    Legend legend = Legend(100, 500);

    Map enemyMap = Map(770, 100, 1);
    Map* playerMap;

    bool winFlag;
    bool playerMove;

    std::map<std::string, Button*> buttons;
    std::vector<MapCoord> damagedDecks;
    
public:

    GameState(std::vector<State*>* statesPointer, Map* playerMap = nullptr);
    ~GameState();

    void botAttack(int i, int j);
    bool checkField(int coorI, int coorJ);
    void ArtificInt();
    void update(sf::RenderWindow* targetWindow = nullptr);
    void render(sf::RenderWindow* targetWindow = nullptr);
};

例如PlacingState.h

代码语言:javascript
复制
    class PlacingState :
    public State
{
private:
    sf::SoundBuffer soundBufferPlacing;
    sf::Sound soundPlacing;
    sf::SoundBuffer soundBufferFlipShip;
    sf::Sound soundFlipShip;

    sf::Text headerText;
    sf::Text helpText;
    sf::Text yourShipsText;

    sf::RectangleShape helpTextBackground;

    Map playerMap = Map(110, 100);

    std::vector<sf::RectangleShape> outMapShipsTable;

    std::map<std::string, Button*> buttons;

    std::vector<OutMapShip> outMapShip;

public:

    PlacingState(std::vector<State*>* statesPointer);
    ~PlacingState();

void initOutMapShips();

void update(sf::RenderWindow* targetWindow = nullptr);
void render(sf::RenderWindow* targetWindow = nullptr);
};
EN

回答 1

Stack Overflow用户

发布于 2022-12-04 20:41:38

如果您的意思是更改所有声音和音乐的全局音量,则可以尝试以下功能:SFML 2.5.1 sf::Listener::setGlobal音量

示例(关闭声音):

代码语言:javascript
复制
sf::Listener::setGlobalVolume(0.0f);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74680571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档