Mercurial > fife-parpg
changeset 493:e29853880e87
Adapted rio_do_hola to use the new SoundManager.
Fixed a bug in the sound manager that caused a sound to not be looped if it did not have a callback assigned to it.
Looping a stream using timers doesn't loop perfectly. I'll fix this in the future.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 07 May 2010 21:46:25 +0000 |
parents | 16ceb3228324 |
children | e241d7553496 |
files | demos/rio_de_hola/run.py demos/rio_de_hola/scripts/world.py engine/python/fife/extensions/soundmanager.py |
diffstat | 3 files changed, 35 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/rio_de_hola/run.py Fri May 07 21:07:27 2010 +0000 +++ b/demos/rio_de_hola/run.py Fri May 07 21:46:25 2010 +0000 @@ -123,17 +123,6 @@ self.listener = ApplicationListener(self.engine, self.world) self.world.load(str(TDS.readSetting("MapFile"))) - self.soundmanager = self.engine.getSoundManager() - self.soundmanager.init() - - if int(TDS.readSetting("PlaySounds")): - # play track as background music - emitter = self.soundmanager.createEmitter() - id = self.engine.getSoundClipPool().addResourceFromFile('music/rio_de_hola.ogg') - emitter.setSoundClip(id) - emitter.setLooping(True) - emitter.play() - def loadSettings(self): """ Load the settings from a python file and load them into the engine.
--- a/demos/rio_de_hola/scripts/world.py Fri May 07 21:07:27 2010 +0000 +++ b/demos/rio_de_hola/scripts/world.py Fri May 07 21:46:25 2010 +0000 @@ -29,6 +29,7 @@ from scripts.common.eventlistenerbase import EventListenerBase from fife.extensions.loaders import loadMapFile from fife.extensions.savers import saveMapFile +from fife.extensions.soundmanager import SoundManager from agents.hero import Hero from agents.girl import Girl from agents.cloud import Cloud @@ -82,6 +83,9 @@ self.instance_to_agent = {} self.dynamic_widgets = {} + self.soundmanager = SoundManager(self.engine) + self.music = None + def show_instancemenu(self, clickpoint, instance): """ Build and show a popupmenu for an instance that the player @@ -136,6 +140,9 @@ """ Clear the agent information and reset the moving secondary camera state. """ + if self.music: + self.music.stop() + self.map, self.agentlayer = None, None self.cameras = {} self.hero, self.girl, self.clouds, self.beekeepers = None, None, [], [] @@ -147,6 +154,7 @@ """ Load a xml map and setup agents and cameras. """ + self.filename = filename self.reset() self.map = loadMapFile(filename, self.engine) @@ -155,6 +163,18 @@ self.initAgents() self.initCameras() + if int(TDS.readSetting("PlaySounds")): + # play track as background music + self.music = self.soundmanager.createSoundEmitter('music/rio_de_hola.ogg') + self.music.looping = True + self.music.gain = 128.0 + self.music.play() + + self.waves = self.soundmanager.createSoundEmitter('sounds/waves.ogg') + self.waves.looping = True + self.waves.gain = 16.0 + self.waves.play() + def initAgents(self): """ Setup agents.
--- a/engine/python/fife/extensions/soundmanager.py Fri May 07 21:07:27 2010 +0000 +++ b/engine/python/fife/extensions/soundmanager.py Fri May 07 21:46:25 2010 +0000 @@ -212,7 +212,6 @@ @param clip The SoundEmitter to be played """ - if clip.fifeemitter: if clip.callback: if clip.timer: @@ -224,7 +223,7 @@ def real_callback(c, e, g): c() e.stop() - e.setGain(g) + e.setGain(float(g)/255.0) e.play() clip.callback = cbwa(real_callback, clip.callback, clip.fifeemitter, clip.gain) @@ -232,10 +231,21 @@ else: repeat = 1 - clip.timer = fife_timer.delayCall(clip.duration, clip.callback) - #clip.timer.start() + clip.timer = fife_timer.Timer(clip.duration, clip.callback, repeat) + clip.timer.start() + else: + if clip.looping: + def real_callback(e, g): + e.stop() + e.setGain(float(g)/255.0) + e.play() + + clip.callback = cbwa(real_callback, clip.fifeemitter, clip.gain) + clip.timer = fife_timer.Timer(clip.duration, clip.callback, 0) + clip.timer.start() + - clip.fifeemitter.setGain(clip.gain) + clip.fifeemitter.setGain(float(clip.gain)/255.0) clip.fifeemitter.play() else: clip = self.createSoundEmitter(clip.name)