From 31d10b7c1a3c199d90eed02e0dbf1e3771609830 Mon Sep 17 00:00:00 2001 From: march3 Date: Sat, 11 Mar 2023 21:05:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=AA=E9=98=B3=E7=B3=BB=E4=B8=89=E4=BD=93?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simulators/ursina_simulator.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/simulators/ursina_simulator.py b/simulators/ursina_simulator.py index b82c061..09359f9 100644 --- a/simulators/ursina_simulator.py +++ b/simulators/ursina_simulator.py @@ -7,7 +7,7 @@ # python_version :3.8 # ============================================================================== # pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ursina -from ursina import Ursina, window, Entity, Grid, Mesh, camera, color, mouse, Vec2, Vec3, load_texture, held_keys +from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, load_texture, held_keys from ursina.prefabs.first_person_controller import FirstPersonController from simulators.views.ursina_view import UrsinaView, UrsinaPlayer @@ -110,6 +110,32 @@ class UrsinaSimulator(Simulator): self.cosmic_background(cosmic_bg) EditorCamera() + + pause_handler = Entity(ignore_paused=True) + + # 按空格键则暂停 + def pause_handler_input(key): + time_scales = [1, 10, 20, 30] + if key == 'space': + application.paused = not application.paused # Pause/unpause the game. + elif key == 'tab': + # application.time_scale 属性控制游戏时间流逝的速度。 + # 具体来说,它是一个浮点数,用于调整游戏时间流逝速度的比例,其默认值为 1.0,表示正常速度。 + # 当你将它设置为小于 1.0 的值时,游戏时间会变慢,而设置为大于 1.0 的值时,游戏时间则会变快。 + for idx, time_scale in enumerate(time_scales): + if int(application.time_scale) == time_scale: + if idx < len(time_scales) - 1: + application.time_scale = time_scales[idx + 1] + break + else: + application.time_scale = 1 + print(application.time_scale) + + pause_handler.input = pause_handler_input + # 加载中文字体文件 + Text.default_font = 'simsun.ttc' + key_info_str = "方位控制[QWEASD + 鼠标] 暂停控制[空格] 移动速度[Tab]" + key_info = Text(text=key_info_str, position=(-0.8, 0.5), origin=(-1, 1), background=True) self.app.run() -- GitLab