【发布时间】:2020-01-08 20:03:18
【问题描述】:
运行基本游戏时,如下图,在pycharm中运行时屏幕不会更新。甚至不会加载背景颜色。但是,当从终端运行时,程序运行良好。为什么是这样?
注意:我已经使用 pycharm 包管理器安装了 Pygame
import sys, pygame
pygame.init()
size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
ball = pygame.image.load("ship.bmp")
ballrect = ball.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
【问题讨论】: