![](/img/trans.png)
[英]Anyone know why the sprites aren't rendering in my pygames program?
[英]Why doesn't my program show sprites with images?
我復制了 1 個程序並更改了圖像上的幾何形狀,但是,我的程序沒有顯示它們。 怎么了? * 我復制他用自己的代碼解決一些問題
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()
您沒有繪制精靈,請執行以下操作:
all_sprites.draw(displaysurface)
在all_sprites.update()
之后
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.