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, we're going to make use of function overloading. If we think about how we may want to use this function, we might either want to pass an already created sound buffer into the component or pass a path to one and create...