i was making a game for class so i was following a tuto , here it is : text
and i got stuck at the min : 21:52 where my code is correct yet im having the black pygame window only (the white sprites aren’t showing) and i couldn’t figure out the reason why.
here’s my main:
from settings import *
from Level import level
from pytmx.util_pygame import load_pygame
from os.path import join
#import os
class Game:
def __init__(self):
pygame.init()
self.display_surface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption('Get The Loaf Back')
self.tmx_maps = {0: load_pygame(join('Code', '..', 'Graphics', 'tmx', 'Map.tmx'))}
self.current_stage = level(self.tmx_maps[0])
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
self.current_stage.run()
pygame.display.update()
if __name__ == '__main__':
game = Game()
game.run()
here’s the level class:
from settings import *
from sprites import Sprite
class level:
def __init__(self,tmx_map):
self.display_surface = pygame.display.get_surface()
# groups:
self.all_sprites = pygame.sprite.Group()
self.setup(tmx_map)
def setup(self, tmx_map):
print(tmx_map)
for x,y,surf in tmx_map.get_layer_by_name('Terrain 1').tiles():
Sprite((x*TILE_SIZE,y*TILE_SIZE), surf, self.all_sprites)
def run(self):
self.display_surface.fill('black')
self.all_sprites.draw(self.display_surface)
the sprites class:
from settings import *
class Sprite(pygame.sprite.Sprite):
def __init__(self, pos, surf, Groups):
super().__init__(Groups)
self.image = pygame.Surface([TILE_SIZE, TILE_SIZE])
self.image.fill('white')
self.rect = self.image.get_frect(topleft = pos)
and the settings:
import pygame, sys
from pygame.math import Vector2 as vector
WINDOW_WIDTH, WINDOW_HEIGHT = 800, 600
TILE_SIZE = 24
ANIMATION_SPEED = 6
help TvT !
New contributor
Imene Mouloudj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.