Playing a sound function
Collisions with enemies and items are processed in the main game class. So, it's here that we will place the function to play sound effects. Add the following function declaration to Game.h
:
/** * Plays the given sound effect, with randomized parameters./ */ void PlaySound(sf::Sound& sound, sf::Vector2f position = { 0.f, 0.f });
This function takes two parameters: we take the sound that we want to play as a reference, to avoid an expensive copy, and we also include a parameter for the position where we want to play the sound. Note that we've given the position parameter a default value of { 0.f, 0.f }
. Therefore, it can be ignored should we wish to do so. We'll cover exactly what this parameter does when we create spatialized ...
Get Procedural Content Generation for C++ Game Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.