Voxel Game Maker

Docs Quick code

Sound

Sounds from code and nodes: everywhere or from a spot in the world, pitch, looping sound sources that follow objects, switching them on and off, and music.

Sounds in the game are 3D: one played from a spot is louder close by, quieter further away, silent past its range, and comes from its side (left or right) as the camera turns.

#Playing a sound

play("door")                    -- from this object
play("coin", 0.5)               -- half volume
play("jump", 1, 1.5)            -- higher pitch
play_at("boom", object("barrel"))
play_at("splash", vec(4, 0, 7)) -- from a tile
stop_sound("door")              -- stop_sound() stops all

In a level script, play plays at the player. Pitch 2 is an octave up, 0.5 an octave down. vec(x, level, z) is a tile.

A sound is a built-in name ("door", "coin", "boom", "blip"…) or the name or id of one you made in the Sound tab.

A different pitch each time makes repeated sounds (footsteps, hits) sound less robotic:

play("pop", 1, 0.9 + randf() * 0.2)   -- between 0.9 and 1.1

#Looping sound sources

A Sound behavior set to Plays: on a loop puts a sound on an object: a campfire's crackle, a waterfall, a buzzing lamp. It follows the object as it moves (a humming robot, a cart). From code, switch it on and off:

object("fire").sound_on(false)   -- off
object("fire").sound_on()        -- on again

loop_at starts a looping sound from code, at an object (it follows it) or a tile. Keep the handle to stop it:

local hum = loop_at("zap", self, 8)   -- heard within 8 tiles
wait(5)
stop_loop(hum)

-- Your own "Rain" sound, following the player:
local rain = loop_at("Rain", player, 4, 0.6)
Function Does
loop_at(sound, where, range = 12, volume = 1, pitch = 1) Starts a looping sound at an object (it follows it), the player or a tile. Gives a handle.
stop_loop(handle) Stops it. Every loop stops when the player leaves the level.
obj.sound_on(on = true) Switches the object's looping Sound behavior on or off.

#Volume and music

volume("music", 0.3)    -- "music", "sound" or "all"
music("boss_theme")     -- "" = the level's own
music_fade("calm", 3)   -- over 3 seconds

#Without code

Code Node
play("door") Action ▸ Play sound (From: this object)
play_at("boom", object("barrel")) Play sound, From: the object named…
(the same loudness wherever the player is) Play sound, From: everywhere
play("jump", 1, 1.5) Play sound, Pitch 1.5
play("pop", 1, 0.9 + randf() * 0.2) Play sound, Random pitch 0.1
obj.sound_on(false) Action ▸ Sound on / off
music("boss") Action ▸ Change music

The Sound behavior has Pitch and Random pitch too.