Skip to content

Commit

Permalink
Merge pull request #44 from tong/update-sound
Browse files Browse the repository at this point in the history
Update sound example project
  • Loading branch information
luboslenco authored Jan 18, 2022
2 parents a4b62d4 + 352d446 commit 2eb80ab
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
Binary file added sound/Bundled/hit0.wav
Binary file not shown.
Binary file added sound/Bundled/hit1.wav
Binary file not shown.
Binary file added sound/Bundled/hit2.wav
Binary file not shown.
2 changes: 1 addition & 1 deletion sound/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 32 additions & 0 deletions sound/Sources/arm/SoundControl.hx
Original file line number Diff line number Diff line change
@@ -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;
});
}
});
});
}
}
Binary file modified sound/sound.blend
Binary file not shown.

0 comments on commit 2eb80ab

Please sign in to comment.