Thanh điều chỉnh âm lượng (volume bar) cho Krpano, kết hợp cùng hệ thống âm thanh bạn đã có trước đó:
✅ TÍNH NĂNG MỚI:
-
✅ Thanh kéo điều chỉnh âm lượng (0–100%)
-
✅ Cập nhật trực tiếp âm lượng khi kéo
-
✅ Tương thích với hệ thống
playsound(...) -
✅ Tự động áp dụng cho mọi scene có âm thanh
🧩 CẤU TRÚC BỔ SUNG
1. 📦 Biến lưu giá trị âm lượng
<var name="sound_volume" value="1.0" />
2. 🎚️ Layer thanh âm lượng
<layer name=”volume_slider_bg”
type=”container”
width=”100″
height=”10″
bgcolor=”0x888888″
align=”righttop”
x=”200″ y=”30″
onclick=”set_volume_by_pos(mouse.x);” /><layer name=”volume_slider_fill”
width=”100″
height=”10″
bgcolor=”0x00ff00″
align=”righttop”
x=”200″ y=”30″
maskchildren=”true” />
3. 🔁 Action xử lý kéo/thay đổi âm lượng
<action name=”set_volume_by_pos”>
calc(volume_ratio, mouse.x / layer[volume_slider_bg].width);
clamp(volume_ratio, 0, 1);
set(sound_volume, volume_ratio);
set(layer[volume_slider_fill].width, volume_ratio * 100);
updatesoundvolume();
</action><action name=”updatesoundvolume”>
if(!sound_muted, setsoundvolume(bg, sound_volume); );
</action>
4. 🎵 Cập nhật trong các hàm playsound từng scene:
Ví dụ scene 1:
<action name="playscene1_audio">
stopsound(bg);
if(!sound_muted,
playsound(bg, "sounds/scene1.mp3");
setsoundvolume(bg, sound_volume);
);
set(global.scene_audio, 'scene1');
</action>
Tương tự thêm setsoundvolume(...) vào các playscene2_audio, playscene3_audio…
5. 🎨 Gợi ý cải tiến UI:
-
Có thể thay fill bằng gradient (
bgcolor="0x00ccff") hoặc thay bằng ảnh nền/thanh trượt. -
Bạn có thể thêm nút tăng/giảm âm lượng ±10% nếu không muốn dùng thanh kéo.
📌 Tóm lại:
-
Thanh kéo điều khiển
sound_volume(0.0 → 1.0) -
Áp dụng vào
setsoundvolume(...)cho mỗi audio -
Cập nhật trực tiếp ngay khi kéo hoặc nhấn vào thanh
Xem thêm:
























