Creating an audio component

The final component that we're going to create is an audio component. Now, this is the first component that we'll create from scratch. However, our experience with the two previous components should make this one easy to implement.

Defining the behavior of an audio component

This is slightly different from our past components. Instead of encapsulating existing behavior, we need to define it. We're going to create a simple audio component, and the only behavior that we're going to have is the ability to play a single sound effect. For this, we'll require a single variable to hold the sound object, a function to set a sound buffer, and a function to play the sound.

In the function that will be used to set the sound buffer, ...

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.