Previous Thread  Next Thread

chat icon Sounds in BGE, play packed sound file

przemekk

Posted: Wed Apr 04, 2012 1:24 pm
Joined: 25 Jan 2011
Posts: 9
There is a possibility to use aud module to play the sound file. It is easy to load the file from disk. But how to load the file from the resource packed into the blend file?

In Blender i can do something like that
Code:

    import aud
    import bpy
    device = aud.device()

    factory = bpy.data.sounds['39068__alienbomb_.000'].factory
    GameLogic.snd_4 = aud.Factory.buffer(factory)


But in Game Engine the module bpy is not available.

So the question is how to create the factory for file stored as packed resource in Game Engine. Any suggestions?[/code]
Reply with quote


przemekk

Posted: Wed Apr 04, 2012 10:23 pm
Joined: 25 Jan 2011
Posts: 9
The easiest sollution (thanks to Dalai) is to create actuators with sounds and to get the factory from the actuators, like this:

Code:

co = GameLogic.getCurrentController()
act = co.actuators['sound_1']

import aud
device = aud.device()
factory = act.sound
snd_handle = device.play(factory)

Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group