i'm trying to get this pytmx work for a few days, but i just can't seem to get how to go on about it, all i want is to load all the layers and make a few layers to be Rects here, i'm just trying to make it blit on the screen, but that isn't working either
import pygame
import pytmx
pygame.init()
W, H = 800, 400
FPS = 60
win = pygame.display.set_mode((W, H), 0, 32)
pygame.display.set_caption('trying to make this work somewhow')
game_map = pytmx.load_pygame('map/map.tmx')
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
win.fill((146, 244, 200))
for layer in game_map.visible_layers:
for x, y, gid, in layer:
tile = game_map.get_tile_image_by_gid(gid)
win.blit(tile, (x * 16, y * 16))
pygame.display.update()
pygame.quit()
Not all the tiles have an image (
pygame.Surface
). Just evaluate iftile
is notNone
:Alternatively, you can draw a colored rectangle at the position of the tile: