我该如何修复我的程序? Pygame一直无法正常工作

时间:2018-04-19 19:18:49

标签: pygame

我正在制作游戏,但它不起作用。我是pygame的新手,所以我觉得我在代码中做了愚蠢的事。 (它打开了pygame窗口,但是不起作用。)

有问题的代码:

from pygame import image
import time
import os
import subprocess
import pygame
from pygame.locals import*
from pygame import mixer
pygame.event.pump
def image(imagename):
    img = pygame.image.load(imagename)
    black = (0, 0 ,0 )
    w = 1251
    h = 584
    screen = pygame.display.set_mode((w, h))
    screen.fill((black))
    running = 1
    while running:
        screen.fill((black))
        screen.blit(img,(0,0))
        pygame.display.flip()
def backstory():
    pygame.init;
    image(imagename='backtory.')
    time.sleep(25)    
def title():
    pygame.init()
    image(imagename='title_screen.jpg')
    time.sleep(3)
    backstory()
title()
for event in pygame.event.get():
    if event.type == MOUSEBUTTONUP:
        None

1 个答案:

答案 0 :(得分:1)

“只是不行”并没有告诉我们多少,但看着代码我认为我得到了你想要做的。这是一些固定的代码,错误的行注释掉了。确保您也在image(imagename='backtory.')中修复了图像文件名。

from pygame import image
import time
import os
import subprocess
import pygame
from pygame.locals import*
from pygame import mixer
pygame.event.pump
def image(imagename):
    img = pygame.image.load(imagename)
    black = (0, 0 ,0 )
    w = 1251
    h = 584
    screen = pygame.display.set_mode((w, h))
    screen.fill((black))
    #running = 1
    #while running:
    #    screen.fill((black))
    screen.blit(img,(0,0))
    pygame.display.flip()
def backstory():
    # pygame.init;
    image(imagename='backstory.jpg')
    time.sleep(25)    
def title():
    pygame.init()
    image(imagename='title_screen.jpg')
    time.sleep(3)
    backstory()

title()
for event in pygame.event.get():
    if event.type == MOUSEBUTTONUP:
        None