Dec-29-2019, 08:35 AM
(Dec-27-2019, 05:01 PM)nilamo Wrote: I've never used it, but I see this in the docs:Quote:Load with pygame surfaces:
>>> from pytmx.util_pygame import load_pygame >>> tmxdata = load_pygame("map.tmx")
So instead of pytmx.load_pygame, trypytmx.util_pygame.load_pygame
.
But also, the source for pytmx just imports submodules (source), so what you're doing should work. How are you importing the module?
I have been importing it like this:
from pytmx import *I tried what you said, but now I'm getting this error:
Traceback (most recent call last): File "/Users/.../Desktop/MyRPG/main.py", line 5172, in <module> g = Game() File "/Users/.../Desktop/MyRPG/main.py", line 16, in __init__ self.load_data() File "/Users/.../Desktop/MyRPG/main.py", line 62, in load_data self.map = TiledMap(path.join(map_folder, 'outdoor.tmx')) File "/Users/.../Desktop/MyRPG/tilemap.py", line 22, in __init__ tm = pytmx.util_pygame.load_pygame NameError: name 'pytmx' is not definedMy code looks like this now:
import pygame as pg from pytmx.util_pygame import load_pygame from settings import * class TiledMap: def __init__(self, filename): tm = pytmx.util_pygame.load_pygame self.width = tm.width * tm.tilewidth self.height = tm.height * tm.tileheight self.tmxdata = load_pygame("outdoor.tmx") def render(self, surface): ti = self.tmxdata.get_tile_image_by_grid for layer in self.tmxdata.visible_layers: if isinstance(layer, pytmx.TiledTileLayer): for x, y, gid, in layer: tile = ti(gid) if tile: surface.blit(tile, (x * self.tmxdata.tilewidth, y * self.tmxdata.tileheight)) def make_map(self): temp_surface = pg.Surface((self.width, self.height)) self.render(temp_surface) return temp_surfaceAnd in the main.py file I use this to load the map: (still the same)
self.map = TiledMap(path.join(map_folder, 'outdoor.tmx')) self.map_img = self.map.make_map() self.map_rect = self.map_img.get_rect()Do you know, how I could fix this? Thanks