I created a small map and was able to open it in pygame, I had to rename the names and paths of the tmx and tsx files, everything worked out for me, but I tried to use a non-absolute path, that is, so that it starts from the working directory, I understand that it is “. …” in tsx files. But nothing worked for me, as soon as I did not change the path
my path looks like this:
main.py
background.py
map →
field.tmx
Forest.tsx
gentle forest (48x48 resize) v01.png
Tree1.png
Tree1.tsx
from pathlib import Path
from pytmx.util_pygame import load_pygame
class Background:
def __init__(self, filename, x=0, y=0):
self.map = Path('map', filename)
self.x = x
self.y = y
def draw(self, camera, screen):
map_data = load_pygame(self.map)
for layer in map_data:
for tile in layer.tiles():
x_pixel = tile[0] * 48 + self.x
y_pixel = tile[1] * 48 + self.y
screen.blit(tile[2], (-camera.rect[0] + x_pixel, -camera.rect[1] + y_pixel))
How can I correctly specify the path in the files and possibly in the background.py file so that everything works correctly?