运行以下基本游戏时,在运行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()
答案 0 :(得分:0)
看起来像解释器问题,请转到“文件”->“设置”->“项目解释器”->“添加”(+符号)并安装PyGame,或选择默认(正在运行的环境)环境。应该可以