Last active
March 30, 2017 05:58
-
-
Save mjago/188964f13a39813afecea75a43372f67 to your computer and use it in GitHub Desktop.
example of Mix_LoadWAV_RW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "../src/sdl" | |
require "../src/mixer" | |
SDL.init(SDL::Init::VIDEO | SDL::Init::AUDIO); at_exit { SDL.quit } | |
SDL::Mixer.init(SDL::Mixer::Init::MP3); at_exit { SDL::Mixer.quit } | |
SDL::Mixer.open | |
chunk = {} of String => LibMixer::Mix_Chunk* | |
names = %w(high medium low scratch) | |
names.each do |name| | |
rwops = LibSDL.rw_from_file("samples/data/#{name}.wav", "rb") | |
chunk[name] = LibMixer.load_wav_rw(rwops, 1) | |
end | |
loop do | |
case event = SDL::Event.wait | |
when SDL::Event::Keyboard | |
case event.sym | |
when .key_1? then SDL::Mixer.play_wav(chunk["high"]) | |
when .key_2? then SDL::Mixer.play_wav(chunk["medium"]) | |
when .key_3? then SDL::Mixer.play_wav(chunk["low"]) | |
when .key_4? then SDL::Mixer.play_wav(chunk["scratch"]) | |
when .q?, SDL::Event::Quit then break | |
end if event.keyup? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment