Skip to content

Ch 9. Using Sound ideal for UI clicks #26

Description

@kyuhyunp

When any button is activated, a sound plays.

void Button::activate()
{
	...
	mSounds.play(SoundEffect::Button);
}

Currently, the button's volume differs based on x and y values.

void SoundPlayer::play(SoundEffect::ID effect)
{
	play(effect, getListenerPosition());
}

If we use the code below, the sound volume for each button remains the same, which is more adequate for UI buttons.

void SoundPlayer::play(SoundEffect::ID effect)
{
	mSounds.push_back(sf::Sound(mSoundBuffers.get(effect)));
	sf::Sound& sound = mSounds.back();

	sound.setRelativeToListener(true); // ignore world coordinates
	sound.setAttenuation(0.f);         // no distance fade

	sound.play();
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions