sound effect
This commit is contained in:
parent
c6e2f85edd
commit
e98e6aeffc
2
README
2
README
|
@ -32,7 +32,7 @@ class SampleGame(Game):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
SampleGame().play()
|
SampleGame().run()
|
||||||
|
|
||||||
|
|
||||||
License
|
License
|
||||||
|
|
|
@ -48,3 +48,27 @@ class Audio(GameChild):
|
||||||
if sound not in self.original_volumes.keys():
|
if sound not in self.original_volumes.keys():
|
||||||
self.original_volumes[sound] = sound.get_volume()
|
self.original_volumes[sound] = sound.get_volume()
|
||||||
sound.set_volume(self.original_volumes[sound] * self.volume)
|
sound.set_volume(self.original_volumes[sound] * self.volume)
|
||||||
|
|
||||||
|
|
||||||
|
class SoundEffect(GameChild, Sound):
|
||||||
|
|
||||||
|
def __init__(self, parent, path, volume=1.0):
|
||||||
|
GameChild.__init__(self, parent)
|
||||||
|
Sound.__init__(self, path)
|
||||||
|
self.display_surface = self.get_display_surface()
|
||||||
|
self.initial_volume = volume
|
||||||
|
self.set_volume(volume)
|
||||||
|
|
||||||
|
def play(self, loops=0, maxtime=0, fade_ms=0, position=None, x=None):
|
||||||
|
self.set_volume(self.initial_volume *
|
||||||
|
self.get_configuration("audio", "sfx-volume"))
|
||||||
|
channel = Sound.play(self, loops, maxtime, fade_ms)
|
||||||
|
if x is not None:
|
||||||
|
position = float(x) / self.display_surface.get_width()
|
||||||
|
if position is not None and channel is not None:
|
||||||
|
channel.set_volume(*self.get_panning(position))
|
||||||
|
return channel
|
||||||
|
|
||||||
|
def get_panning(self, position):
|
||||||
|
return 1 - max(0, ((position - .5) * 2)), \
|
||||||
|
1 + min(0, ((position - .5) * 2))
|
||||||
|
|
Loading…
Reference in New Issue