Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with pytmx
#6
I tried out what you said @metulburr and @michael1789 but it is not working.
Now I am getting this error:

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 6, in <module>
    pytmx.load_pygame()
TypeError: load_pygame() missing 1 required positional argument: 'filename'
The code looks like this now:


import pygame as pg
#from pytmx.util_pygame import load_pygame
import pytmx
from settings import *

pytmx.load_pygame()

def collide_hit_rect(one, two):
    return one.hit_rect.colliderect(two.rect)

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 = tm = load_pygame(filename, pixelalpha=True) #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_surface
In the sprites.py file I just imported that collide_hit_rect thing, because I need it there.
I don't know why it is not working.
I made a new map and didn't move any of the files.
Hope you guys can help me out.

Thanks. Happy New Year by the way. :-)
Reply


Messages In This Thread
Problems with pytmx - by Piethon - Dec-24-2019, 11:27 AM
RE: Problems with pytmx - by nilamo - Dec-27-2019, 05:01 PM
RE: Problems with pytmx - by Piethon - Dec-29-2019, 08:35 AM
RE: Problems with pytmx - by metulburr - Dec-29-2019, 01:20 PM
RE: Problems with pytmx - by michael1789 - Dec-29-2019, 06:25 PM
RE: Problems with pytmx - by Piethon - Jan-02-2020, 08:47 AM
RE: Problems with pytmx - by metulburr - Jan-02-2020, 12:20 PM
RE: Problems with pytmx - by michael1789 - Jan-02-2020, 03:14 PM
RE: Problems with pytmx - by Piethon - Jan-03-2020, 11:06 AM
RE: Problems with pytmx - by michael1789 - Jan-03-2020, 01:43 PM
RE: Problems with pytmx - by Piethon - Jan-03-2020, 05:55 PM
RE: Problems with pytmx - by michael1789 - Jan-03-2020, 07:13 PM
RE: Problems with pytmx - by Piethon - Jan-04-2020, 08:58 AM
RE: Problems with pytmx - by michael1789 - Jan-04-2020, 06:09 PM
RE: Problems with pytmx - by metulburr - Jan-04-2020, 03:37 PM
RE: Problems with pytmx - by Piethon - Jan-05-2020, 10:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display isometric maps with pytmx? Piethon 18 10,452 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