Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with pytmx
#11
(Jan-03-2020, 01:43 PM)michael1789 Wrote: I just noticed that line 6 you have:
pytmx.load_pygame()
I don't have that, and it's not in his example. That might be the issue. Take it out and see if that works.

Nope. Sadly it is not working. The people here in the forum told me to do this. Now I'm getting this error:

  File "main.py", line 5171, in <module>
    g = Game()
  File "main.py", line 15, in __init__
    self.load_data()
  File "main.py", line 61, in load_data
    self.map = TiledMap(path.join(map_folder, 'map1.tmx'))
  File "/Users/.../Desktop/MyRPG/tilemap.py", line 24, in __init__
    self.width = tm.width * tm.tilewidth
AttributeError: 'function' object has no attribute 'width'
The name of the map is map1.tmx. I checked that multiple times.
Reply
#12
try replacing your code with what I have.
class TileMap:
    def __init__(self, filename):
        tm = load_pygame(filename, pixelalpha=True)
        self.width = tm.width * tm.tilewidth
        self.height = tm.height * tm.tilewidth
        self.tmxdata = tm
They are very different.

Where you define "tm" I think you need "()" at the end.
Reply
#13
(Jan-03-2020, 07:13 PM)michael1789 Wrote: try replacing your code with what I have.
class TileMap:
    def __init__(self, filename):
        tm = load_pygame(filename, pixelalpha=True)
        self.width = tm.width * tm.tilewidth
        self.height = tm.height * tm.tilewidth
        self.tmxdata = tm
They are very different.

Where you define "tm" I think you need "()" at the end.

I replayed it with your code and now I have this error:


Traceback (most recent call last):
  File "/Users/.../Desktop/MyRPG/main.py", line 5171, in <module>
    g = Game()
  File "/Users/.../Desktop/MyRPG/main.py", line 15, in __init__
    self.load_data()
  File "/Users/.../Desktop/MyRPG/main.py", line 61, in load_data
    self.map = TiledMap(path.join(map_folder, 'map1.tmx'))
  File "/Users/.../Desktop/MyRPG/tilemap.py", line 29, in __init__
    tm = load_pygame(filename, pixelalpha=True)
NameError: name 'load_pygame' is not defined
It says that load_pygame is not defined. You said, that at the tm thing I'd need a () at the end. But you don't have that either. So I tried it also this way:

def __init__(self, filename):
        tm = pytmx.util_pygame.load_pygame()
        #tm = load_pygame(filename, pixelalpha=True)
        self.width = tm.width * tm.tilewidth
        self.height = tm.height * tm.tilewidth
        self.tmxdata = tm
There I am getting a different error, which is:

Traceback (most recent call last):
  File "/Users/.../Desktop/MyRPG/main.py", line 5, in <module>
    from sprites import *
  File "/Users/.../Desktop/MyRPG/sprites.py", line 4, in <module>
    from tilemap import collide_hit_rect
  File "/Users/.../Desktop/MyRPG/tilemap.py", line 28
    def __init__(self, filename):
                                ^
IndentationError: unindent does not match any outer indentation level
I checked that it is intentioned, but although I'm getting this error above.
Reply
#14
I would suggest to make a repo with your entire code structure including all resources. In this way we can run your exact program and tinker with it directly to find the issue.
Recommended Tutorials:
Reply
#15
[quote='Piethon' pid='101493' dateline='1578128305']

It says that load_pygame is not defined. You said, that at the tm thing I'd need a () at the end. But you don't have that either. So I tried it also this way:

        tm = load_pygame(filename, pixelalpha=True)
Yes I did, it just had stuff in it.


At this point, I'd suggest going back to the video and following the links to his actual code from that lesson, downloading and working with that.
Reply
#16
Thank you a lot. It works now.

I know that the TiledMap class I made is just for loading orthogonal maps.
How do I have to change this code, that I can load isometric maps?

class TiledMap:
    def __init__(self, filename):
        tm = pytmx.load_pygame(filename, pixelalpha=True)
        self.width = tm.width * tm.tilewidth
        self.height = tm.height * tm.tileheight
        self.tmxdata = tm

    def render(self, surface):
        ti = self.tmxdata.get_tile_image_by_gid
        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_surface
I don't have much experience with pytmx, so I don't know, what I can change, that it is able to load isometric maps. Thanks for your help guys. :-)

Piethon
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display isometric maps with pytmx? Piethon 18 9,698 Feb-19-2020, 04:33 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020