我的精灵不会显示?? Pygame
My sprite won't show ?? Pygame
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的新手,正在"trying"制作游戏,我需要一些帮助,我不知道为什么我的精灵不显示。感谢您提前回复!
您永远不会创建 world
class.
的实例
删除这一行:
Group.add(self)
然后创建 world
的实例并将其添加到 group_sprites
组:
the_world = world()
group_sprites = pygame.sprite.Group(the_world)
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的新手,正在"trying"制作游戏,我需要一些帮助,我不知道为什么我的精灵不显示。感谢您提前回复!
您永远不会创建 world
class.
删除这一行:
Group.add(self)
然后创建 world
的实例并将其添加到 group_sprites
组:
the_world = world()
group_sprites = pygame.sprite.Group(the_world)