在sdl中创建声音管理器

时间:2014-04-10 16:09:35

标签: c++ audio sdl

#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <iostream>
#include "Constants.h"
#include "Texture2D.h"
#include "GameScreenManager.h"
#include "Audio.h"
using namespace::std;

Audio::Audio(string paths)
{
    gMusic = NULL;

    if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
    {
        cout << "Mixer could not initialise. error: " << Mix_GetError();
    }

    LoadMusic(paths);
    Update();


}


Audio::~Audio()
{
    Mix_FreeMusic(gMusic);
    gMusic = NULL;
}


void Audio::LoadMusic(string path)
{

    gMusic = Mix_LoadMUS(path.c_str());

    if(gMusic == NULL)
    {
        cout << "Failed to load background music! Error: " << Mix_GetError() << endl;
    }
}

bool Audio::Update()
{

    if(Mix_PlayingMusic() == 0)
    {
        Mix_PlayMusic(gMusic, -1);
    }
    return false;
}
到目前为止,这是我的声音管理员。我用Audio :: Audio(“Music / bubble-bobble.mp3”)在源代码中调用它;但它没有发挥任何作用。我认为更新有问题,因为“字符串路径”正在通过和事情发送。有人有什么想法吗?

0 个答案:

没有答案