Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将鼠标锁定在窗口游戏中_Python_Pygame_Mouse - Fatal编程技术网

Python 将鼠标锁定在窗口游戏中

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)

我想在窗口模式下用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):
    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))
它将鼠标放在里面。