简体   繁体   English

为什么我的程序不显示带有图像的精灵?

[英]Why doesn't my program show sprites with images?

I copied 1 program and changed geometric shapes on images, however, my program doesn't show them.我复制了 1 个程序并更改了图像上的几何形状,但是,我的程序没有显示它们。 What's wrong?怎么了? * I copied him to solve some problems with own code * 我复制他用自己的代码解决一些问题

 
vec = pygame.math.Vector2 
HEIGHT = 450
WIDTH = 400
#[...]
displaysurface = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Game")
 
class Player(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__() 
        self.image = pygame.image.load('Sonic.actionp1.png')
        self.rect = self.image.get_rect()
   
        self.pos = vec((10, 385))
        self.vel = vec(0,0)
        self.acc = vec(0,0)
 
# [...]
class platform(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.image.load('platform1.png')
        self.rect = self.image.get_rect(center = (WIDTH/2, HEIGHT - 10))
 
PT1 = platform()
P1 = Player()
platforms = pygame.sprite.Group()
platforms.add(PT1)
all_sprites = pygame.sprite.Group()
all_sprites.add(PT1)
all_sprites.add(P1)
# [...]
 
    P1.move()
    all_sprites.update()
    pygame.display.flip()

You didn't draw the sprites, do:您没有绘制精灵,请执行以下操作:

all_sprites.draw(displaysurface)

after the all_sprites.update()all_sprites.update()之后

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

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