game: allow playing a sfx at non default pitch

This commit is contained in:
Crypto City 2023-04-16 06:19:37 +00:00
parent 6c7fb2fafa
commit 965705d38f
2 changed files with 3 additions and 2 deletions

View File

@ -114,7 +114,7 @@ void Audio::SetSFXVolume(float volume)
audio->SetMasterGain(Urho3D::SOUND_EFFECT, volume);
}
void Audio::PlaySFX(const char *resource)
void Audio::PlaySFX(const char *resource, float pitch)
{
Urho3D::ResourceCache* cache = GetSubsystem<Urho3D::ResourceCache>();
@ -124,6 +124,7 @@ void Audio::PlaySFX(const char *resource)
auto *soundSource = sfx_node.GetOrCreateComponent<Urho3D::SoundSource>(Urho3D::LOCAL);
soundSource->SetAutoRemoveMode(Urho3D::REMOVE_COMPONENT);
soundSource->Play(sound);
soundSource->SetFrequency(soundSource->GetSound()->GetFrequency() * pitch);
}
}

View File

@ -23,7 +23,7 @@ public:
bool SetMusicTrack(const std::vector<std::pair<Urho3D::String, Urho3D::String>> &music);
float GetMusicVolume() const;
void SetMusicVolume(float volume);
void PlaySFX(const char *resource);
void PlaySFX(const char *resource, float pitch = 1.0f);
void SetSFXVolume(float volume);
void PlayAmbience(Urho3D::SoundSource *&ambience_source, const char *resource);
void SetAmbienceParameters(Urho3D::SoundSource *ambience_source, float volume, float pitch);