[英]Running a game which uses Pygame doesn't work in pycharm, but will work when run from terminal
在运行基本游戏(例如以下游戏)时,在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()
看起来像是解释器问题,请转到“文件”->“设置”->“项目解释器”->“添加”(+符号)并安装PyGame,或选择默认(正在运行的环境)环境。 应该管用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.