简体   繁体   English

运行使用Pygame的游戏在pycharm中不起作用,但在从终端运行时将起作用

[英]Running a game which uses Pygame doesn't work in pycharm, but will work when run from terminal

When running a basic game, such as the one below, the screen will not update when ran in pycharm. 在运行基本游戏(例如以下游戏)时,在pycharm中运行时,屏幕不会更新。 Not even the background colour will load. 甚至不会加载背景色。 However when run from terminal the program works fine. 但是,从终端运行时,程序运行正常。 Why is this? 为什么是这样?

Note: I have installed Pygame using the pycharm package manager 注意:我已经使用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()

Looks like interpreter problem, go to File->Settings->Project Interpreter->add(+ symbol) and install PyGame, or choose default(one on which it's running) enviroment. 看起来像是解释器问题,请转到“文件”->“设置”->“项目解释器”->“添加”(+符号)并安装PyGame,或选择默认(正在运行的环境)环境。 Should work 应该管用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM