-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from tong/update-sound
Update sound example project
- Loading branch information
Showing
6 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
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 not shown.