我的精灵不会显示? Pygame的

时间:2015-11-11 06:34:58

标签: python python-3.x pygame sprite 2d-games

import time
import sys
import pygame
from pygame.locals import *
from pygame.sprite import Sprite, Group

pygame.init()

running = False

screen_width = 1280 
screen_height = 720
size = (screen_width, screen_height)
screen = pygame.display.set_mode((size), pygame.FULLSCREEN)
pygame.display.set_caption('Laser Bits')

class world(Sprite):
    def __init__(self):
        Sprite.__init__(self)
        self.image = pygame.image.load('levels/LBMAPPREALPHA1.png')
        self.rect = self.image.get_rect()
        self.rect.x = 0 
        self.rect.y = 0
        Group.add(self)

group_sprites = pygame.sprite.Group()

while running == False:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      running = True

  group_sprites.draw(screen)
  pygame.display.update()

我是Python的新手,我正在“尝试”制作游戏,我需要一些帮助,我不知道为什么我的精灵不会显示。感谢您提前回复!

1 个答案:

答案 0 :(得分:0)

您永远不会创建world类的实例。

删除此行:

Group.add(self)

然后创建world的实例并将其添加到group_sprites组:

the_world = world()
group_sprites = pygame.sprite.Group(the_world) 
相关问题