|
1 | 1 | local test = require("test") |
2 | 2 | local imgui = require("imgui") |
3 | 3 |
|
| 4 | +local SE_NAME = "啊!" |
| 5 | + |
4 | 6 | ---@class test.audio.SoundEffect : test.Base |
5 | 7 | local M = {} |
6 | 8 |
|
7 | 9 | function M:onCreate() |
8 | 10 | local old = lstg.GetResourceStatus() |
9 | 11 | lstg.SetResourceStatus("global") |
10 | | - lstg.LoadSound("啊!", "res/audio/啊!.wav") |
| 12 | + lstg.LoadSound(SE_NAME, "res/audio/啊!.wav") |
11 | 13 | lstg.SetResourceStatus(old) |
| 14 | + self.vol = 1.0 |
| 15 | + self.pan = 0.0 |
12 | 16 | end |
13 | 17 |
|
14 | 18 | function M:onDestroy() |
15 | | - lstg.RemoveResource("global", 5, "啊!") |
| 19 | + lstg.RemoveResource("global", 5, SE_NAME) |
16 | 20 | end |
17 | 21 |
|
18 | 22 | function M:onUpdate() |
19 | 23 | ---@diagnostic disable-next-line: undefined-field |
20 | 24 | local ImGui = imgui.ImGui |
21 | 25 | if ImGui.Begin("Audio: Sound Effect") then |
22 | | - ImGui.Text(("SE State: %s"):format(lstg.GetSoundState("啊!"))) |
| 26 | + ImGui.Text(("SE State: %s"):format(lstg.GetSoundState(SE_NAME))) |
| 27 | + _, self.vol = ImGui.SliderFloat("Volume", self.vol, 0.0, 1.0) |
| 28 | + _, self.pan = ImGui.SliderFloat("Pan", self.pan, -1.0, 1.0) |
23 | 29 | if ImGui.Button("Play") then |
24 | | - lstg.PlaySound("啊!") |
| 30 | + lstg.PlaySound(SE_NAME, self.vol, self.pan) |
25 | 31 | end |
26 | 32 | if ImGui.Button("Pause") then |
27 | | - lstg.PauseSound("啊!") |
| 33 | + lstg.PauseSound(SE_NAME) |
28 | 34 | end |
29 | 35 | if ImGui.Button("Resume") then |
30 | | - lstg.ResumeSound("啊!") |
| 36 | + lstg.ResumeSound(SE_NAME) |
31 | 37 | end |
32 | 38 | if ImGui.Button("Stop") then |
33 | | - lstg.StopSound("啊!") |
| 39 | + lstg.StopSound(SE_NAME) |
34 | 40 | end |
35 | 41 | end |
36 | 42 | ImGui.End() |
|
0 commit comments