I have been working on one of my first ever games, which is a game developed with the html5 canvas element and javascript. I am at the stage where really all I need to do now is add sound and music. here is what I am looking to do:
- A song that plays whenever the game is played, this should also loop.(Basically just a game soundtrack that always plays.)
- A clicking sound effect for when a button is clicked on.
- A sound effect for when the player collects a coin.
- A sound effect for when the player dies.
I know that you can have an html audio file, however this requires the user to click a play button for the music to begin. I was wondering if the follow is possible:
- Add a html audio element.
- Use css to style it to be invisible.
- Create a function in javascript which plays the required sound. So I would call the function which plays the game music from the beginning, and a clicking sound function when a button is presses etc.
Would this be possible or is there a better way entirely to achieve this.