Python 3.x 我不知道';即使没有错误,我也不知道为什么它仍然是空的。

Python 3.x 我不知道';即使没有错误,我也不知道为什么它仍然是空的。,python-3.x,pygame,Python 3.x,Pygame,这是我在pygame中为屏幕编写的代码,但除了黑屏外,什么也没有出现。没有错误,但我是python新手,所以您能告诉我出了什么问题吗 import pygame, sys from pygame.locals import* pygame.init() 我的屏幕 DISPLAYSURF=pygame.display.set_mode((300,200), 0, 32) pygame.display.set_caption('WorldMaker') 颜色 BLACK=(0,0,0) WHI

这是我在pygame中为屏幕编写的代码,但除了黑屏外,什么也没有出现。没有错误,但我是python新手,所以您能告诉我出了什么问题吗

import pygame, sys
from pygame.locals import*

pygame.init()
我的屏幕

DISPLAYSURF=pygame.display.set_mode((300,200), 0, 32)
pygame.display.set_caption('WorldMaker')
颜色

BLACK=(0,0,0)
WHITE=(255,255,255)
RED=(255, 0, 0)
GREEN=(0,255,0)
BLUE=(0,0,255)
YELLOW=(255,255,0)
文本和行

DISPLAYSURF.fill(WHITE)
pygame.draw.line(DISPLAYSURF, BLACK, (0,30), (300,30), 3)
pygame.draw.line(DISPLAYSURF, BLACK, (200,0), (200,200), 3)
myfont=pygame.font.SysFont('Eras Bold ITC', 20)
label = myfont.render('WorldMaker', 1, BLACK)
DISPLAYSURF.blit(label,(50,10))
label1 = myfont.render('Store', 1, BLACK)
DISPLAYSURF.blit(label1,(225,10))
我的精灵

这是我遇到最多麻烦的部分,我想可能是原因,也可能是主回路

class B(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image=pygame.image.load('Character.png').convert()
        self.rect = self.image.get_rect()
        self.rect.topleft=[150,50]

    def update(self):
        self.rect.y +=1

B_list=pygame.sprite.Group()
all_sprites_list = pygame.sprite.Group()
b=B()
B_list.add(b)

#Main Loop
while True:
    B.update(b)
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
            pygame.display.update()

当前屏幕未清除,精灵不绘制

# create a couple units of B(), and save one as the player
player = B()
all_sprites_list = pygame.sprite.Group()
all_sprites_list.add([player, B(), B()])

while True:
    # event handling

    # movement
    all_sprites_list.update()

    # drawing
    screen.fill(Color("white"))
    all_sprites_list.draw(screen)
    pygame.display.update()

提示:白色
红色
是多余的。您可以使用
Color(“red”)
来做同样的事情。

当我键入所有精灵列表时,如果它说我需要两个参数来绘制,我该怎么办。draw()我忘记添加屏幕了。该参数是您的屏幕表面,或您希望将组blit到的任何位置。示例:
所有精灵列表。绘制(屏幕)