mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-24 23:26:45 +00:00
sound callback ok
This commit is contained in:
@@ -54,17 +54,16 @@ namespace BBM
|
||||
this->_soundList[this->_soundIndex].get()->pause();
|
||||
}
|
||||
|
||||
void SoundComponent::setVolume(float &volumeUpdate)
|
||||
void SoundComponent::setVolume(float volumeUpdate)
|
||||
{
|
||||
if (!this->_isSoundLoad.at(this->_soundIndex))
|
||||
return;
|
||||
if (volumeUpdate >= 0) {
|
||||
if (volumeUpdate >= 0 && volumeUpdate <= 1) {
|
||||
this->volume = volumeUpdate;
|
||||
this->_soundList[this->_soundIndex].get()->setVolume(this->volume);
|
||||
for (auto &sound : _soundList)
|
||||
sound.second->setVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
void SoundComponent::setPitch(float &pitch)
|
||||
void SoundComponent::setPitch(float pitch)
|
||||
{
|
||||
if (!this->_isSoundLoad.at(this->_soundIndex))
|
||||
return;
|
||||
@@ -88,4 +87,14 @@ namespace BBM
|
||||
return (this->_soundIndex);
|
||||
}
|
||||
|
||||
void SoundComponent::turnDownVolume()
|
||||
{
|
||||
this->setVolume(SoundComponent::volume - 0.1);
|
||||
}
|
||||
|
||||
void SoundComponent::turnUpVolume()
|
||||
{
|
||||
this->setVolume(SoundComponent::volume + 0.1);
|
||||
}
|
||||
|
||||
} // namespace WAL
|
||||
|
||||
@@ -42,10 +42,16 @@ namespace BBM
|
||||
void pauseSound();
|
||||
|
||||
//! @brief set Sound volume
|
||||
void setVolume(float &);
|
||||
void setVolume(float);
|
||||
|
||||
//! @brief volume -= 0.1
|
||||
void turnDownVolume();
|
||||
|
||||
//! @brief volume += 0.1
|
||||
void turnUpVolume();
|
||||
|
||||
//! @brief set pitch volume
|
||||
void setPitch(float &);
|
||||
void setPitch(float);
|
||||
|
||||
//! @brief is Sound playing
|
||||
bool isPlaying();
|
||||
|
||||
@@ -409,7 +409,13 @@ namespace BBM
|
||||
auto &soundUp = scene->addEntity("sound up button")
|
||||
.addComponent<PositionComponent>(1920 / 1.5, 1080 - 360, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_plus.png")
|
||||
.addComponent<OnClickComponent>()
|
||||
.addComponent<SoundComponent>(sounds)
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
auto &component = entity.getComponent<SoundComponent>();
|
||||
|
||||
component.turnUpVolume();
|
||||
})
|
||||
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
@@ -426,13 +432,19 @@ namespace BBM
|
||||
auto &soundDown = scene->addEntity("sound down button")
|
||||
.addComponent<PositionComponent>(1920 / 3, 1080 - 360, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_minus.png")
|
||||
.addComponent<OnClickComponent>()
|
||||
.addComponent<SoundComponent>(sounds)
|
||||
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_minus.png");
|
||||
})
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
auto &component = entity.getComponent<SoundComponent>();
|
||||
|
||||
component.turnDownVolume();
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
Reference in New Issue
Block a user