瀏覽代碼

add Audio lib

Bastien Sevajol 6 年之前
父節點
當前提交
f710d5ab01
共有 1 個文件被更改,包括 25 次插入0 次删除
  1. 25 0
      synergine2_cocos2d/audio.py

+ 25 - 0
synergine2_cocos2d/audio.py 查看文件

@@ -0,0 +1,25 @@
1
+# coding: utf-8
2
+import typing
3
+
4
+from cocos.audio.pygame.mixer import Sound
5
+
6
+from synergine2_cocos2d.util import PathManager
7
+
8
+
9
+class AudioLibrary(object):
10
+    # name: file_name
11
+    sound_file_paths = {}  # type: typing.Dict[str, str]
12
+
13
+    def __init__(
14
+        self,
15
+        include_paths: typing.List[str],
16
+    ) -> None:
17
+        self._path_manager = PathManager(include_paths)
18
+        self._sounds = {}
19
+
20
+    def get_sound(self, name: str) -> Sound:
21
+        if name not in self._sounds:
22
+            sound_file_name = self.sound_file_paths[name]
23
+            sound_file_path = self._path_manager.path(sound_file_name)
24
+            self._sounds[name] = Sound(sound_file_path)
25
+        return self._sounds[name]