I copied 1 program and changed geometric shapes on images, however, my program doesn't show them. 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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.