Search code examples
pythonpython-3.xpygamesprite2d-games

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()

I'm a newbie at Python and I'm "trying" to make a game and I need some help, I do not know why my sprite won't show. Thank you for your responses in advanced!


Solution

  • You never create an instance of your world class.

    Remove this line:

    Group.add(self)
    

    and then create an instance of world and add it to the group_sprites group:

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