0

I have made a tiled map, but when i try to import it just keeps giving errors i've been trying this for days and still cant resolve the errors

Also forgive me for my english errors

Traceback (most recent call last):
  File "C:\Users\davim\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Users\davim\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "C:\Users\davim\Documents\outros\Programação\Python\Jodo\main.py", line 12, in <module>
    game_map = load_pygame("Testmap.tmx")
  File "C:\Users\davim\AppData\Local\Programs\Python\Python39\lib\site-packages\pytmx\util_pygame.py", line 140, in load_pygame
    return pytmx.TiledMap(filename, *args, **kwargs)
  File "C:\Users\davim\AppData\Local\Programs\Python\Python39\lib\site-packages\pytmx\pytmx.py", line 370, in __init__
    self.parse_xml(ElementTree.parse(self.filename).getroot())
  File "C:\Users\davim\AppData\Local\Programs\Python\Python39\lib\site-packages\pytmx\pytmx.py", line 438, in parse_xml
    self.reload_images()
  File "C:\Users\davim\AppData\Local\Programs\Python\Python39\lib\site-packages\pytmx\pytmx.py", line 461, in reload_images
    loader = self.image_loader(path, colorkey, tileset=ts)
  File "C:\Users\davim\AppData\Local\Programs\Python\Python39\lib\site-packages\pytmx\util_pygame.py", line 99, in pygame_image_loader
    image = pygame.image.load(filename)
FileNotFoundError: No such file or directory.

Here's my code so you can see what is wrong and help me

import pygame
from pygame.locals import *
from pytmx.util_pygame import load_pygame

pygame.init()

# -----Variaveis------
largura = 1000
altura = 600
background = (0,0,0)
screen = pygame.display.set_mode((largura, altura))
game_map = load_pygame("Testmap.tmx")

# ----MapLoader----
images = []

for y in range(50):
    for x in range(50):
        image = game_map.get_tile_image(x,y,0)
        images.append(image)

# Desenhe todos os tiles na tela
i = 0

for y in range(50):
    for x in range(50):
        screen.blit(images[i],(x * 32, y * 32))
        i += 1

# -----Display-----
pygame.display.set_caption('Jodo foda')
tmxdata = load_pygame('Jodo\maps\map.tmx')

# -----Loop-----
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
Brisolo
  • 1
  • 1
  • 1

1 Answers1

0

It appears as though all your problems source from this line: game_map = load_pygame("Testmap.tmx"). The traceback claims that there is no such file in existence. If you are sure the file does exist (double checking wouldn't hurt), try and path to it directly.

This is what a direct path looks like: C:\Users\davim\Documents\outros\Programação\Python\Jodo\Testmap.tmx, and this is a relative path, the file path you are using: Testmap.tmx. Because the file you are referencing doesn't exist in the main python folder (but instead in the documents folder), you sadly do have to do this every single time you load a file in this program.

To sum, change this: game_map = load_pygame("Testmap.tmx") to this: game_map = load_pygame("C:\Users\davim\Documents\outros\Programação\Python\Jodo\Testmap.tmx") (only if that is the path of your file.) and you should be all set.

In the future, if you ever need to path to a file directly, File Explorer can do most of the work for you. Just click on the bar on top, and it will automatically generate the file path, which you then put in front of the file name:

example of clicking on the bar at the top of the file explorer

In my case, the parent folders are C:\Windows\diagnostics\index, and the file name is AppsDiagnostic.xml. The direct path is those two combined: C:\Windows\diagnostics\index\AppsDiagnostic.xml, with an extra backslash in between them.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
User 12692182
  • 927
  • 5
  • 16