Python 将鼠标锁定在窗口游戏中
我想在窗口模式下用Pygame制作一个FPS游戏 我需要能够移动我的相机周围360度和更多没有限制和隐藏光标 我使用了Pygame的Python 将鼠标锁定在窗口游戏中,python,pygame,mouse,Python,Pygame,Mouse,我想在窗口模式下用Pygame制作一个FPS游戏 我需要能够移动我的相机周围360度和更多没有限制和隐藏光标 我使用了Pygame的set_visible和set_pos,但这并不能阻止我的鼠标离开窗口并阻塞屏幕边框 import pygame pygame.init() game_display = pygame.display.set_mode((800,600)) pygame.mouse.set_visible(False) exit = False while (not exit)
set_visible
和set_pos
,但这并不能阻止我的鼠标离开窗口并阻塞屏幕边框
import pygame
pygame.init()
game_display = pygame.display.set_mode((800,600))
pygame.mouse.set_visible(False)
exit = False
while (not exit):
pygame.mouse.set_pos = (400, 300)
mouse_move = (0,0)
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit = True
if event.type == pygame.MOUSEMOTION:
mouse_move = event.rel
if mouse_move != (0,0):
print(mouse_move)
pygame.quit()
你也得打电话
最好允许用户使用Esc或其他键退出,因为他们将无法再单击x按钮来关闭窗口
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
exit = True
顺便说一句:
set_pos
是方法,而不是变量-pygame.mouse.set_pos((400300))
它将鼠标放在里面。