Ability to play sounds centered or positionally.
This commit is contained in:
parent
578eac6811
commit
79afdeadc7
@ -329,7 +329,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
|||||||
AL.vecPos=game.GetWorldOffset()+GetScreenSize()/2;
|
AL.vecPos=game.GetWorldOffset()+GetScreenSize()/2;
|
||||||
AL.OnUserUpdate(fElapsedTime);
|
AL.OnUserUpdate(fElapsedTime);
|
||||||
if (GetKey(olc::Key::P).bPressed){
|
if (GetKey(olc::Key::P).bPressed){
|
||||||
AS_Test.Play(1,1);
|
AS_Test.Play({0,0},1,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto&tile:TileManager::visibleTiles){
|
for(auto&tile:TileManager::visibleTiles){
|
||||||
|
@ -104,8 +104,10 @@ public:
|
|||||||
// Instruct Audio Listener to load this sound (if not loaded already)
|
// Instruct Audio Listener to load this sound (if not loaded already)
|
||||||
void LoadAudioSample(int ID, const char* fileName);
|
void LoadAudioSample(int ID, const char* fileName);
|
||||||
|
|
||||||
|
void PlayCentered(float speed = 1.0f, float vol = 1.0f, bool looping = false, bool paused = false);
|
||||||
|
|
||||||
// Play the Audio Sample, with given parameters
|
// Play the Audio Sample, with given parameters
|
||||||
void Play(float speed = 1.0f, float vol = 1.0f, bool looping = false, bool paused = false);
|
void Play(vf2d pos, float speed = 1.0f, float vol = 1.0f, bool looping = false, bool paused = false);
|
||||||
|
|
||||||
// Pause or Un-Pause - maintains the playback position and handle
|
// Pause or Un-Pause - maintains the playback position and handle
|
||||||
void Pause(bool pauseState = true);
|
void Pause(bool pauseState = true);
|
||||||
@ -136,13 +138,34 @@ void olcPGEX_AudioSource::LoadAudioSample(int ID, const char* fileName)
|
|||||||
AL->LoadAudioSample(ID, fileName);
|
AL->LoadAudioSample(ID, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void olcPGEX_AudioSource::Play(float speed, float vol, bool looping, bool paused)
|
void olcPGEX_AudioSource::PlayCentered(float speed, float vol, bool looping, bool paused)
|
||||||
|
{
|
||||||
|
// Set parameters
|
||||||
|
fPlaySpeed = speed;
|
||||||
|
fVolume = vol;
|
||||||
|
bLooping = looping;
|
||||||
|
bPaused = paused;
|
||||||
|
this->pos = pos;
|
||||||
|
|
||||||
|
// Assign a handle to this instance of the sound we are about to play
|
||||||
|
handle = AL->soloud.play(*AL->GetAudioSampleByID(nID)->wav, fVolume, 0.0f, bPaused);
|
||||||
|
|
||||||
|
// Set speed and looping
|
||||||
|
AL->soloud.setRelativePlaySpeed(handle, fPlaySpeed);
|
||||||
|
AL->soloud.setLooping(handle, looping);
|
||||||
|
|
||||||
|
// Update Play status
|
||||||
|
bIsPlaying = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void olcPGEX_AudioSource::Play(vf2d pos, float speed, float vol, bool looping, bool paused)
|
||||||
{
|
{
|
||||||
// Set parameters
|
// Set parameters
|
||||||
fPlaySpeed = speed;
|
fPlaySpeed = speed;
|
||||||
fVolume = vol*std::max(0.f,abs(1-std::min(1.0f,(AL->GetDistance(pos)/1024.f))));
|
fVolume = vol*std::max(0.f,abs(1-std::min(1.0f,(AL->GetDistance(pos)/1024.f))));
|
||||||
bLooping = looping;
|
bLooping = looping;
|
||||||
bPaused = paused;
|
bPaused = paused;
|
||||||
|
this->pos = pos;
|
||||||
|
|
||||||
// Assign a handle to this instance of the sound we are about to play
|
// Assign a handle to this instance of the sound we are about to play
|
||||||
handle = AL->soloud.play(*AL->GetAudioSampleByID(nID)->wav, fVolume, 0.0f, bPaused);
|
handle = AL->soloud.play(*AL->GetAudioSampleByID(nID)->wav, fVolume, 0.0f, bPaused);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user