examples: update play-opus to latest Audio API
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
9a96820926
commit
7ccfcefa96
1 changed files with 9 additions and 3 deletions
|
|
@ -20,6 +20,7 @@ pub const Mod = mach.Mod(@This());
|
|||
|
||||
pub const events = .{
|
||||
.init = .{ .handler = init },
|
||||
.after_init = .{ .handler = afterInit },
|
||||
.deinit = .{ .handler = deinit },
|
||||
.tick = .{ .handler = tick },
|
||||
.audio_state_change = .{ .handler = audioStateChange },
|
||||
|
|
@ -32,9 +33,8 @@ pub const components = .{
|
|||
sfx: Opus,
|
||||
|
||||
fn init(core: *mach.Core.Mod, audio: *mach.Audio.Mod, app: *Mod) !void {
|
||||
// Initialize audio module, telling it to send our module's .audio_state_change event when an
|
||||
// entity's sound stops playing
|
||||
audio.send(.init, .{app.event(.audio_state_change)});
|
||||
audio.send(.init, .{});
|
||||
app.send(.after_init, .{});
|
||||
|
||||
const bgm_fbs = std.io.fixedBufferStream(assets.bgm.bit_bit_loop);
|
||||
const sfx_fbs = std.io.fixedBufferStream(assets.sfx.death);
|
||||
|
|
@ -63,6 +63,12 @@ fn init(core: *mach.Core.Mod, audio: *mach.Audio.Mod, app: *Mod) !void {
|
|||
core.send(.start, .{});
|
||||
}
|
||||
|
||||
fn afterInit(audio: *mach.Audio.Mod, app: *Mod) void {
|
||||
// Configure the audio module to send our app's .audio_state_change event when an entity's sound
|
||||
// finishes playing.
|
||||
audio.state().on_state_change = app.event(.audio_state_change);
|
||||
}
|
||||
|
||||
fn deinit(core: *mach.Core.Mod, audio: *mach.Audio.Mod) void {
|
||||
audio.send(.deinit, .{});
|
||||
core.send(.deinit, .{});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue