Console::Audio

console 0.2.0 · app/console/audio.rb · 175 lines · view source

Console::Audio -- sound effects and music.

DragonRuby has no play method: you write into args.audio keyed by a symbol of your choosing, or push a one-shot into args.outputs.sounds. This module wraps both so a cart says sfx(:jump) and never touches a file path.

sfx :jump
sfx :hit, pitch: 0.8, gain: 0.6
music :title
music_gain 0.4
stop_music

Music is tracked under one stable key, so calling music again crossfades by replacement instead of stacking loops. SFX are one-shots and self-clean.

def initialize(args)
line 23
def args
line 33

registration

def register(name, path)

teach the console where a sound lives

The path is resolved against the booted cart, so register :jump, 'sounds/jump.wav' inside a cart means that cart's own file.

def register_all(hash)
line 47
def music_library(hash)
line 51
def resolve(name)
line 55
def missing_names
line 66

sfx

def sfx(name, options = {})

Play a one-shot. gain and pitch are floats (DragonRuby warns otherwise).

music

def music(name, options = {})

Start (or swap) the looping music track. Repeating the same name is a no-op, so this is safe to call every frame.

def stop_music
line 112
def music_name
line 119
def music_playing?
line 123
def music_gain(value)
line 127
def track_gain(value)

Volume of the currently playing track only.

global

def mute
line 149
def unmute
line 156
def muted?
line 162
def toggle_mute
line 166
def stop_all

Stop everything this console owns, leaving other audio alone.