mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 13:43:41 +00:00
added channels to sound
This commit is contained in:
parent
cb1b5af358
commit
b321051ac5
@ -48,17 +48,18 @@ class SoundManager
|
||||
//! \returns a pointer to Mix_Chunk, which is added to a map in the AssetManager
|
||||
//! \sa AssetManager::AddSound(std::string id, const char* path)
|
||||
|
||||
static void playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume); //!< Plays sound effects
|
||||
static void playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume, int channel); //!< Plays sound effects
|
||||
//! handles if sounds can overlap, how often they can loop, as well as the volume at which the specified sound effect should play
|
||||
static void playMusic(Game* game, std::string sound, int loops, int volume, int ms); //<! Plays music
|
||||
//! handles how often the track should loop, as well as the volume at which the specified track should play
|
||||
|
||||
static void setVolume(int volume); //!< Volume handling for the entire program
|
||||
static void setSoundVolume(int volume, int channel); //!< Volume handling for the entire program
|
||||
static void setMusicVolume(int volume);
|
||||
|
||||
static void pauseSound();
|
||||
static void pauseSound(int channel);
|
||||
static void pauseMusic();
|
||||
|
||||
static void restartSound();
|
||||
static void restartSound(int channel);
|
||||
static void restartMusic();
|
||||
|
||||
static void fadeOutMusic(int ms);
|
||||
|
||||
@ -33,24 +33,24 @@ void KeyboardController::update()
|
||||
if (keystates[this->up]) {
|
||||
transform->direction.y = -1;
|
||||
sprite->playAnimation(WALK);
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME);
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1);
|
||||
}
|
||||
if (keystates[this->left]) {
|
||||
transform->direction.x = -1;
|
||||
sprite->playAnimation(WALK);
|
||||
sprite->setDirection(Direction::LEFT);
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME);
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1);
|
||||
}
|
||||
if (keystates[this->down]) {
|
||||
transform->direction.y = 1;
|
||||
sprite->playAnimation(WALK);
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME);
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1);
|
||||
}
|
||||
if (keystates[this->right]) {
|
||||
transform->direction.x = 1;
|
||||
sprite->playAnimation(WALK);
|
||||
sprite->setDirection(Direction::RIGHT);
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME);
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1);
|
||||
}
|
||||
|
||||
if (keystates[this->fire]) {
|
||||
|
||||
@ -13,7 +13,7 @@ void ProjectileComponent::init()
|
||||
{
|
||||
transformComponent = &entity->getComponent<TransformComponent>();
|
||||
transformComponent->direction = direction;
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "throw_egg", true, PLAY_ONCE, MAX_VOLUME);
|
||||
SoundManager::playSound(this->entity->getManager().getGame(), "throw_egg", true, PLAY_ONCE, MAX_VOLUME, -1);
|
||||
}
|
||||
|
||||
void ProjectileComponent::update()
|
||||
|
||||
@ -48,11 +48,11 @@ Mix_Chunk* SoundManager::loadSound(const char* fileName)
|
||||
}
|
||||
|
||||
// TODO: using a string here is probably... a less than stellar method, figure out how to change this
|
||||
void SoundManager::playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume)
|
||||
void SoundManager::playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume, int channel)
|
||||
{
|
||||
if(!canOverlap)
|
||||
{
|
||||
if (Mix_Playing(-1) != 0)
|
||||
if (Mix_Playing(channel) != 0)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ void SoundManager::playSound(Game* game, std::string sound, bool canOverlap, int
|
||||
std::cerr << "Error adjusting volume: " << Mix_GetError() << std::endl;
|
||||
}
|
||||
|
||||
if (Mix_PlayChannel(-1, game->assets->getSound(sound), loops) == -1)
|
||||
if (Mix_PlayChannel(channel, game->assets->getSound(sound), loops) == -1)
|
||||
{
|
||||
std::cerr << "Error playing sound '" << sound << "': " << Mix_GetError() << std::endl;
|
||||
}
|
||||
@ -89,14 +89,19 @@ void SoundManager::playMusic(Game* game, std::string music, int loops, int volum
|
||||
}
|
||||
}
|
||||
|
||||
void SoundManager::setVolume(int volume)
|
||||
void SoundManager::setSoundVolume(int volume, int channel)
|
||||
{
|
||||
Mix_Volume(-1, volume);
|
||||
Mix_Volume(channel, volume);
|
||||
}
|
||||
|
||||
void SoundManager::pauseSound()
|
||||
void SoundManager::setMusicVolume(int volume)
|
||||
{
|
||||
Mix_Pause(-1);
|
||||
Mix_VolumeMusic(volume);
|
||||
}
|
||||
|
||||
void SoundManager::pauseSound(int channel)
|
||||
{
|
||||
Mix_Pause(channel);
|
||||
}
|
||||
|
||||
void SoundManager::pauseMusic()
|
||||
@ -104,9 +109,9 @@ void SoundManager::pauseMusic()
|
||||
Mix_PauseMusic();
|
||||
}
|
||||
|
||||
void SoundManager::restartSound()
|
||||
void SoundManager::restartSound(int channel)
|
||||
{
|
||||
Mix_Resume(-1);
|
||||
Mix_Resume(channel);
|
||||
}
|
||||
|
||||
void SoundManager::restartMusic()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user