当前位置: 首页>>代码示例>>Python>>正文


Python Sound.set_volume方法代码示例

本文整理汇总了Python中pygame.mixer.Sound.set_volume方法的典型用法代码示例。如果您正苦于以下问题:Python Sound.set_volume方法的具体用法?Python Sound.set_volume怎么用?Python Sound.set_volume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.mixer.Sound的用法示例。


在下文中一共展示了Sound.set_volume方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _make_sample

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import set_volume [as 别名]
def _make_sample(slot):
    """
        Makes Sound instances tuple and sets Sound volumes
    """
    global SAMPLES_DIR
    sample_file = os.path.join(SAMPLES_DIR, slot['sample'])
    sample = Sound(sample_file)
    sample.set_volume(slot.get('volume', 100) / 100.0)
    return sample
开发者ID:rajcze,项目名称:battery,代码行数:11,代码来源:utils.py

示例2: __init__

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import set_volume [as 别名]
class Audio:

    PLAY = 0
    PAUSE = 1
    STOP = 2
    GRAVITY = 0
    DEATH = 1

    def __init__(self):
        mixer.init(frequency=44100, size=-16, channels=4, buffer=128)
        self._background_s = Sound(os.path.join("res", "background.ogg"))
        self._background_s.set_volume(0.8)
        self._grav_fxs_s = [
            Sound(os.path.join("res", "grav1.wav")),
            Sound(os.path.join("res", "grav2.wav")),
            Sound(os.path.join("res", "grav3.wav")),
        ]
        for s in self._grav_fxs_s:
            s.set_volume(0.1)
        self._death_s = Sound(os.path.join("res", "death.wav"))

        self._background_channel = mixer.Channel(0)
        self._fx_channel = mixer.Channel(1)
        self.effect_playing = False
        self.bg_playing = False

    def bg(self, state=0):
        if state == self.PLAY:
            if self._background_channel.get_sound() == None:
                self._background_channel.play(self._background_s, loops=-1, fade_ms=250)
            else:
                self._background_channel.unpause()
            self.bg_playing = True
        elif state == self.PAUSE:
            self._background_channel.pause()
            self.bg_playing = False
        else:
            self._background_channel.stop()
            self.bg_playing = False

    def fx(self, state=0, fx=0):
        if state == self.PLAY:
            if fx == self.GRAVITY:
                if self._fx_channel.get_sound() not in self._grav_fxs_s:
                    self._fx_channel.stop()
                    self._fx_channel.play(choice(self._grav_fxs_s), loops=0, fade_ms=0)
            else:
                if self._fx_channel.get_sound() != self._death_s:
                    self._fx_channel.stop()
                    self._fx_channel.play(self._death_s, loops=0, fade_ms=0)

        elif state == self.PAUSE:
            self._fx_channel.pause()
        else:
            self._fx_channel.stop()
开发者ID:dwinings,项目名称:Grow,代码行数:57,代码来源:gaudio.py

示例3: __init__

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import set_volume [as 别名]
class Sound:
    """Class wrapping ``pygame.mixer.Sound`` with the ability to enable/disable sound globally

    Use this instead of ``pygame.mixer.Sound``. The interface is fully transparent.
    """
    def __init__(self, source):
        if config.SOUND:
            self.sound = OldSound(source)

    def play(self, loops=0, maxtime=0, fade_ms=0):
        if config.SOUND:
            self.sound.play(loops, maxtime, fade_ms)

    def stop(self):
        if config.SOUND:
            self.sound.stop()

    def fadeout(self, time):
        if config.SOUND:
            self.sound.fadeout(time)

    def set_volume(self, value):
        if config.SOUND:
            self.sound.set_volume(value)

    def get_volume(self):
        if config.SOUND:
            return self.sound.get_volume()

    def get_num_channels(self):
        if config.SOUND:
            return self.sound.get_num_channels()

    def get_length(self):
        if config.SOUND:
            return self.get_length()

    def get_raw(self):
        if config.SOUND:
            return self.sound.get_raw()
开发者ID:pstray,项目名称:rpi_lcars,代码行数:42,代码来源:sound.py

示例4: __init__

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import set_volume [as 别名]
class Rocket:

    def __init__(self,
                 obj_file,
                 gravity,
                 maximum_speed,
                 maximum_acceleration,
                 maximum_roll_rate,
                 controls,
                 blaster_list,
                 blaster_color):

        self.gravity=gravity
        
        self.maximum_speed=maximum_speed
        self.maximum_acceleration=maximum_acceleration
        self.maximum_roll_rate=maximum_roll_rate
        
        self.controls=controls

        self.blaster_list=blaster_list
        
        self.blaster_color=blaster_color
        
        self.angle=0.0

        self.model=OBJ(config.basedir+"/assets", obj_file)

        self.position=Vector2D(0.0,0.0)
        self.velocity=Vector2D(0.0,0.0)

        self.bounding_box=BoundingPolygon( (Vector2D(-1.0, 1.0),
                                            Vector2D(1.0, 1.0),
                                            Vector2D(1.0, -1.0),
                                            Vector2D(0.0, -2.0),
                                            Vector2D(-1.0, -1.0)) )

        self.weight=1.0

        self.beam=Beam()
        self.plume=Plume()

        self.blaster_sound=Sound(config.basedir+"/assets/Laser_Shoot_2.wav")
        self.engine_sound=Sound(config.basedir+"/assets/engine.wav")
        self.engine_sound.set_volume(0.075)

        self.fire_counter=3

    @gl_utilities.sprites_configuration
    def _draw_sprites(self):
        self.beam.draw()
        self.plume.draw()

    @gl_utilities.shader_configuration(config.basedir+"/shaders/vertex.txt", 
                                       config.basedir+"/shaders/fragment.txt")
    def _draw_shader(self):
        glPushMatrix()

        glRotate(self.angle,0.0,0.0,1.0)
        glRotate(90.0,-1.0,0.0,0.0)

        glCallList(self.model.gl_list)
        glPopMatrix()

    def draw(self):

        glPushMatrix()

        glTranslate(-self.position.x, -self.position.y, 0.0)

        self._draw_sprites()
        self._draw_shader()

        glPopMatrix()

#        _draw_bounding_box(self.bounding_box)

    def _fire(self):
#    angle, position, blaster_color, blaster_list):

        direction=Vector2D(math.sin(math.radians(self.angle)),
                           -math.cos(math.radians(self.angle)))

        self.blaster_list.append(Blaster(self.blaster_color,
                                         self.position+2.001*direction,
                                         direction))

    def update(self,clock):

        seconds_passed=clock.get_time()/1000.0

        self.angle += (self.maximum_roll_rate*
                       self.controls.get_rotate()*
                       seconds_passed)

        if 0 < self.controls.get_throttle():
            if self.plume.is_off():
                self.plume.on()

            self.engine_sound.play()
#.........这里部分代码省略.........
开发者ID:aukeman,项目名称:pygame_rockets,代码行数:103,代码来源:rocket.py

示例5: ScreenMain

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import set_volume [as 别名]
class ScreenMain(LcarsScreen):
    def setup(self, all_sprites):
        areset(a)
        all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1.png"),
                        layer=0)
        
        # panel text
        all_sprites.add(LcarsText(colours.BLACK, (11, 75), "MOSF"),
                        layer=1)
        all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "LONG RANGE PROBE", 2.5),
                        layer=1)
        all_sprites.add(LcarsText(colours.BLACK, (54, 667), "192 168 0 3"),
                        layer=1)

        # date display
        self.stardate = LcarsText(colours.BLACK, (444, 506), "", 1)
        self.lastClockUpdate = 0
        all_sprites.add(self.stardate, layer=1)

        # permanent buttons        
        all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler),
                        layer=1)
        all_sprites.add(LcarsBlockSmall(colours.ORANGE, (211, 16), "ABOUT", self.aboutHandler),
                        layer=1)
        all_sprites.add(LcarsBlockLarge(colours.BLUE, (145, 16), "DEMO", self.demoHandler),
                        layer=1)
        all_sprites.add(LcarsBlockHuge(colours.PEACH, (249, 16), "EXPLORE", self.exploreHandler),
                        layer=1)
        all_sprites.add(LcarsElbow(colours.BEIGE, (400, 16), "MAIN"),
                        layer=1)
        
        # Sounds
        self.beep_1 = Sound("assets/audio/panel/201.wav")
        self.fwoosh = Sound("assets/audio/panel/250.m4a")
        self.fwoosh.set_volume(1.0)
        self.fwoosh.play()
        time.sleep(6)
#         Sound("assets/audio/panel/220.wav").play()

        #-----Screens-----#

        
        # Main Screen ------------------------------------------------------------------------------------
        #116-800: 684 : 342
        #90-440 : 350 : 175
        all_sprites.add(LcarsText(colours.WHITE, (192, 174), "WELCOME", 1.5),
                        layer=3)
        all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TO THE Museum of Science Fiction", 1.5),
                        layer=3)
        all_sprites.add(LcarsText(colours.BLUE, (286, 174), "LONG RANGE PROBE EXHIBIT", 1.5),
                        layer=3)
        all_sprites.add(LcarsText(colours.BLUE, (330, 174), "LOOK AROUND", 1.5),
                        layer=3)
        self.main_text = all_sprites.get_sprites_from_layer(3)

        # Logout Screen ----------------------------------------------------------------------------------
        self.logout_image = LcarsImage("assets/intro_screen.png", (0,0), self.mainHandler)
        self.logout_image.visible = False
        all_sprites.add(self.logout_image, layer=49) #Previously layer2

        self.logout_gif = LcarsGifImage("assets/gadgets/MOSF.gif", (90, 330), 35)
        self.logout_gif.visible = False
        all_sprites.add(self.logout_gif, layer=49) #Previously 2

        all_sprites.add(LcarsText(colours.ORANGE, (270, -1), "LONG RANGE PROBE", 3), layer=50)
        all_sprites.add(LcarsText(colours.ORANGE, (390, -1), "TOUCH TERMINAL TO PROCEED", 1.5), layer=50)
        self.logout_text = all_sprites.get_sprites_from_layer(50)
        self.hideText(self.logout_text)
        

        # Demo Screen ------------------------------------------------------------------------------------



        # About Screen -----------------------------------------------------------------------------------
        self.purpose = LcarsButton(colours.GREY_BLUE, (107, 127), "PURPOSE", self.purposeHandler)
        self.purpose.visible = False
        all_sprites.add(self.purpose, layer=4)

        self.details = LcarsButton(colours.ORANGE, (107, 262), "DETAILS", self.detailsHandler)
        self.details.visible = False
        all_sprites.add(self.details, layer=4)

        self.personnel = LcarsButton(colours.GREY_BLUE, (107, 398), "PERSONNEL", self.personnelHandler)
        self.personnel.visible = False
        all_sprites.add(self.personnel, layer=4)

        self.sources = LcarsButton(colours.ORANGE, (107, 533), "SOURCES", self.sourcesHandler)
        self.sources.visible = False
        all_sprites.add(self.sources, layer=4)

        
        # Purpose
        all_sprites.add(LcarsText(colours.WHITE, (192, 140), "To inspire", 1.25),
                        layer=5)
        #all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TO THE Museum of Science Fiction", 1),
        #                layer=3)
        #all_sprites.add(LcarsText(colours.BLUE, (286, 174), "LONG RANGE PROBE EXHIBIT", 1),
        #                layer=3)
        #all_sprites.add(LcarsText(colours.BLUE, (330, 174), "LOOK AROUND", 1),
#.........这里部分代码省略.........
开发者ID:psychomugs,项目名称:lcars_probe,代码行数:103,代码来源:main.py


注:本文中的pygame.mixer.Sound.set_volume方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。