几天前我发布了一个类似的问题,但我已经改进了这个问题:当我在同一个事件循环中同时有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()发布于 2011-09-26 23:09:35
不要在每次事件中都更新屏幕,这会大大减慢你的程序。在我的电脑上它太慢了,我无法理解鼠标事件。只需移动几行代码就可以解决这个问题,它运行得很好。
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)
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))
screen.fill((0, 0, 0))
pygame.display.flip()
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.poshttps://stackoverflow.com/questions/7556940
复制相似问题