pygame.MOUSEBUTTONDOWN pygame.VIDEORESIZE 错误?
几天前我发布了类似的问题,但我已经改进了问题: 当我在同一个事件循环中同时使用 MOUSEBUTTONDOWN 和 VIDEORESIZE 时,它不起作用...当我单击鼠标时,它还会打印仅在 MOUSEBUTTONUP 事件发生时才应该打印的语句...尝试一下,这个问题是杀了我..
import pygame
from pygame.locals import *
from sys import exit
LEFT = 1
size = 520,630
running = 1
screen = pygame.display.set_mode(size, RESIZABLE, 32)
#screen = pygame.display.set_mode((size))
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = 0
if event.type == pygame.VIDEORESIZE:
size = event.size
pygame.display.set_caption("Window resized to "+str(event.size))
if event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
print "You pressed the left mouse button at (%d, %d)" % event.pos
if event.type == pygame.MOUSEBUTTONUP and event.button == LEFT:
print "You released the left mouse button at (%d, %d)" % event.pos
screen = pygame.display.set_mode(size, RESIZABLE, 32)
screen.fill((0, 0, 0))
pygame.display.flip()
I posted a similar question a few days ago but i have refined the problem:
when i have both MOUSEBUTTONDOWN and VIDEORESIZE in the same event loop it doent work... when i click the mouse down it also prints the statement which should only get printed when the MOUSEBUTTONUP event occurs.... TRY it your selves this problem is killing me..
import pygame
from pygame.locals import *
from sys import exit
LEFT = 1
size = 520,630
running = 1
screen = pygame.display.set_mode(size, RESIZABLE, 32)
#screen = pygame.display.set_mode((size))
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = 0
if event.type == pygame.VIDEORESIZE:
size = event.size
pygame.display.set_caption("Window resized to "+str(event.size))
if event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
print "You pressed the left mouse button at (%d, %d)" % event.pos
if event.type == pygame.MOUSEBUTTONUP and event.button == LEFT:
print "You released the left mouse button at (%d, %d)" % event.pos
screen = pygame.display.set_mode(size, RESIZABLE, 32)
screen.fill((0, 0, 0))
pygame.display.flip()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要在每次事件时都更新屏幕,这会大大减慢您的程序速度。在我的计算机上它太慢了,我无法理解鼠标事件。只需移动几行代码即可修复该问题并且运行良好。
Don't update the screen at every event, it slows down your program considerably. It's so slow on my computer I can't make any sense of the mouse events. Just moving a couple of lines of your code fixes that and it runs fine.