Skip to content
Download

6. Sound

Select the sounds folder, in Resources, and drag tiro.wav, explosao.wav and dano.wav from the zip. The ▶ next to each sound plays the file.

Inspector of a sound.

On Player, one line after spawn and another in hurt, after taking the life:

objects/Player.lua
spawn("Bullet", self.x, self.y - 8, "Tiros")
Audio.play("tiro", { volume = 0.4 })
-- ...
game.lives = game.lives - 1
Audio.play("dano")

On Enemy, in kill:

objects/Enemy.lua
game.score = game.score + self.pontos
Audio.play("explosao", { volume = 0.5 })
self:destroy()

The sound name is the file name, without the extension. volume goes from 0 to 1. Background music: playMusic, in Sound.

Next part: 7. Game over