30 PlaySound - JcerelusDev/CanvasGameJs GitHub Wiki

How to use playSound method

Considering using the same game object

The class PlaySound has 3 parameters and 2 methods :

1.- run to play the sound

2.- stop to stop the sound

new PlaySound(xsound,volume,type)

type is only use for game music background and type should be a string of "loop"

First of all what is that method

that method is used to add sound to the game with one line of code

Example :

first you have to hold it in a variable so that you can use it later


let game = new Stage()

let tick = game.preload("tick","klink.m4a")

 let collectSound = new PlaySound(tick,0.2)
 collectSound.run()