python - 如何在 python 街机上使用 set_exclusive_mouse?
问题描述
任何人都可以在街机库中提供这种方法的示例吗?我看了网站上的解释,但我不明白。我期待它具有可以使对象在没有光标位置的情况下随鼠标运动移动的功能。谢谢!
解决方案
可能你不需要使用set_exclusive_mouse
. 相反,隐藏鼠标光标set_mouse_visible
并使用捕获光标位置on_mouse_motion
:
import arcade
class MyGame(arcade.Window):
def __init__(self):
super().__init__(600, 400)
self.set_mouse_visible(False)
self.mouse_x = None
self.mouse_y = None
def on_draw(self):
arcade.start_render()
if self.mouse_x and self.mouse_y:
arcade.draw_text(f'Cursor position: {self.mouse_x} {self.mouse_y}', 0, 370, arcade.color.RED, font_size=25)
arcade.draw_circle_filled(self.mouse_x, self.mouse_y, 18, arcade.color.RED)
def on_mouse_motion(self, x, y, dx, dy):
self.mouse_x = x
self.mouse_y = y
MyGame()
arcade.run()
例子:
推荐阅读
- html - 在 Bootstrap 中删除填充/边距
- python - Matplotlib - 图相互堆叠
- swift - Swift4滚动UITableview后,动画UITableview框架是错误的
- spring-boot - 骆驼 springboot 和 hawtio 集成
- google-analytics - 要在更多设置中设置的 Google 跟踪代码管理器字段?
- php - 提交表单后未显示成功消息
- docker - 创建 dokcer 映像以挂载 nfs 服务器时无法启动 rcpbind
- list - Haskell 中映射函数的 Lambda 演算等效项是什么?
- php - 如何通过PHP将一列json对象拆分为更多列
- javascript - 为什么过滤函数返回空数组?