回答編集履歴
1
追記
test
CHANGED
@@ -7,3 +7,45 @@
|
|
7
7
|
|
8
8
|
のいずれかでしょうか。
|
9
9
|
また、元のMusicPlayerクラスには、止めるメソッドがなさそうなので、付けてるといいんじゃないですかね。
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
追記
|
14
|
+
|
15
|
+
こんな感じじゃないですかね。
|
16
|
+
|
17
|
+
```python
|
18
|
+
import pyxel
|
19
|
+
import pygame
|
20
|
+
|
21
|
+
|
22
|
+
class MusicPlayer:
|
23
|
+
def __init__(self,filename):
|
24
|
+
pygame.mixer.init()
|
25
|
+
pygame.mixer.music.load(filename)
|
26
|
+
|
27
|
+
def loop(self,time=0.0):
|
28
|
+
pos = pygame.mixer.music.get_pos()
|
29
|
+
if int(pos) == -1:
|
30
|
+
pygame.mixer.music.play(-1,time)
|
31
|
+
|
32
|
+
def start(self, count=1):
|
33
|
+
pygame.mixer.music.play(count)
|
34
|
+
|
35
|
+
def stop(self):
|
36
|
+
pygame.mixer.music.stop()
|
37
|
+
|
38
|
+
|
39
|
+
class App:
|
40
|
+
def __init__(self):
|
41
|
+
# ~中略~
|
42
|
+
self.music_player = MusicPlayer('music.mp3')
|
43
|
+
|
44
|
+
#音楽をこの画面で流したい
|
45
|
+
def update_game_scene(self):
|
46
|
+
self.music_player.loop(time=x.x) #x.xは再生開始場所を指定
|
47
|
+
# ~中略~
|
48
|
+
if pyxel.btnp(pyxel.KEY_SPACE):
|
49
|
+
pass
|
50
|
+
```
|
51
|
+
|