diff --git a/sound/Bundled/hit0.wav b/sound/Bundled/hit0.wav new file mode 100644 index 0000000..0c2cd67 Binary files /dev/null and b/sound/Bundled/hit0.wav differ diff --git a/sound/Bundled/hit1.wav b/sound/Bundled/hit1.wav new file mode 100644 index 0000000..97d48cc Binary files /dev/null and b/sound/Bundled/hit1.wav differ diff --git a/sound/Bundled/hit2.wav b/sound/Bundled/hit2.wav new file mode 100644 index 0000000..f8de89a Binary files /dev/null and b/sound/Bundled/hit2.wav differ diff --git a/sound/README.md b/sound/README.md index acf3b33..bf1bcc2 100644 --- a/sound/README.md +++ b/sound/README.md @@ -1,5 +1,5 @@ - Keyboard `Space`: load/play bundled sound -- Keyboard `A`: toggle play/pause speaker +- Keyboard `A`: toggle play/pause positional speaker - https://github.com/armory3d/armory/wiki/sound - https://api.armory3d.org/iron/object/SpeakerObject.html diff --git a/sound/Sources/arm/SoundControl.hx b/sound/Sources/arm/SoundControl.hx new file mode 100644 index 0000000..5004ee0 --- /dev/null +++ b/sound/Sources/arm/SoundControl.hx @@ -0,0 +1,32 @@ +package arm; + +import iron.object.SpeakerObject; +import iron.system.Input; + +class SoundControl extends iron.Trait { + + public function new() { + super(); + notifyOnInit(() -> { + final mouse = Input.getMouse(); + final keyboard = Input.getKeyboard(); + final speaker = iron.Scene.active.getSpeaker('Speaker'); + trace(speaker.data); + notifyOnUpdate( () -> { + if(keyboard.started('a')) { + trace('Toggle speaker (${!speaker.paused})'); + speaker.paused ? speaker.play() : speaker.pause(); + } + if(keyboard.started('space')) { + // Randomly play one of the three hit sounds + final sound = 'hit${Std.random(3)}.wav'; + trace('Play $sound'); + iron.data.Data.getSound(sound, (s:kha.Sound) -> { + var channel = iron.system.Audio.play(s); + channel.volume = 0.4; + }); + } + }); + }); + } +} diff --git a/sound/sound.blend b/sound/sound.blend index a7f6cf5..0a55dcc 100644 Binary files a/sound/sound.blend and b/sound/sound.blend differ