Source code for morse.actuators.sound

import logging; logger = logging.getLogger("morse." + __name__)
from morse.core import blenderapi
from morse.core.actuator import Actuator
from morse.helpers.components import add_data

[docs]class Sound(Actuator): """ This actuator is a simple On/Off sound. Based on `Sound <>`_ actuator. """ _name = "Sound" _short_desc = "A simple sound actuator" add_data('mode', "stop", 'string', "mode, enum in ['play','pause','stop']") def __init__(self, obj, parent=None):"%s initialization" % # Call the constructor of the parent class Actuator.__init__(self, obj, parent) self.local_data['mode'] = obj['mode'] self._last_mode = None'Component initialized')
[docs] def default_action(self): """ Apply ``play`` to this actuator. """ # get the Blender Logic Controller contr = blenderapi.controller() # if self.local_data['mode'] == self._last_mode: return act = contr.actuators[-1] contr.activate(act) # enables 3D effect (!) if self.local_data['mode'] == 'play': act.startSound() elif self.local_data['mode'] == 'pause': act.pauseSound() elif self.local_data['mode'] == 'stop': act.stopSound() # new last mode self._last_mode = self.local_data['mode']