【问题标题】:My sprite won't show ?? Pygame我的精灵不会显示??游戏
【发布时间】:2016-02-12 05:45:27
【问题描述】:
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 的新手,我正在“尝试”制作游戏,我需要一些帮助,我不知道为什么我的精灵不会显示。感谢您提前回复!

【问题讨论】:

  • running 有点误导:P

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


【解决方案1】:

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

删除这一行:

Group.add(self)

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

the_world = world()
group_sprites = pygame.sprite.Group(the_world) 

【讨论】:

    猜你喜欢
    • 2016-11-29
    • 2016-06-13
    • 1970-01-01
    • 2020-03-13
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多