当我在窗口上移动光标时,我的pygame窗口仅更新
仅当我的光标移动且位于窗口上方时,我的 Pygame 窗口才会更新。
import pygame
window_length = 1000
window_height = 600
dimensions = (window_length, window_height)
window = pygame.display.set_mode(dimensions)
WHITE = (255, 255, 255)
BLACK = (0,0,0)
main = True
x = 0
y = 0
while main:
for event in pygame.event.get():
if event.type == pygame.QUIT:
main = False
x += 1
#redraw background
pygame.draw.rect(window, BLACK, (0,0, window_length, window_height))
pygame.draw.rect(window, WHITE, (x, y, 100, 100))
pygame.display.update()
pygame.quit()
我尝试移动东西但没有任何效果。
My Pygame window will only update if my cursor is moving and is above the window.
import pygame
window_length = 1000
window_height = 600
dimensions = (window_length, window_height)
window = pygame.display.set_mode(dimensions)
WHITE = (255, 255, 255)
BLACK = (0,0,0)
main = True
x = 0
y = 0
while main:
for event in pygame.event.get():
if event.type == pygame.QUIT:
main = False
x += 1
#redraw background
pygame.draw.rect(window, BLACK, (0,0, window_length, window_height))
pygame.draw.rect(window, WHITE, (x, y, 100, 100))
pygame.display.update()
pygame.quit()
I tried moving things around but nothing worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取消缩进事件循环下的代码。现在,您仅在有事件需要循环时才执行绘图代码,例如鼠标移动。
它应该看起来像:
Unindent the code under the event loop. Right now, you're only doing the drawing code when there are events to loops through, like your mouse moving.
It should look like: