""" arcade声音测试例子 (现在可能只在windows系统中有用) """ import arcade import os SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SCREEN_TITLE = "arcade声音测试例子" class MyGame(arcade.Window): """ Main sound test class """ def __init__(self): """ Initializer """ # 调有父类初始化方法创建窗口 super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) # 设置工作目录 file_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(file_path) # 设置背景颜色 arcade.set_background_color(arcade.color.BLACK) def setup(self): self.shoot_sound = arcade.sound.load_sound("sounds/laser1.wav") print("音效加载完毕") def on_draw(self): """Render the screen""" arcade.start_render() # 准备在屏幕显示的文本 text = "单击鼠标播放声音\nwww.lixingqiu.com" # 渲染文本 arcade.draw_text(text, 150, 300, arcade.color.WHITE, 30,font_name='simhei') def on_mouse_press(self, x, y, button, modifiers): """当按键时调用这个方法""" # 播放音效 arcade.sound.play_sound(self.shoot_sound) def update(self, delta_time): """animations""" def main(): test = MyGame() test.setup() arcade.run() if __name__ == "__main__": main()