I am trying to use pyGame and pyTMX in pyCharm; however, I am getting an annoying error message whenever I try to run the program. The following code was
def get_tile_properties(self, x, y, layer):
""" Return the tile image GID for this location
:param x: x coordinate
:param y: y coordinate
:param layer: layer number
:rtype: python dict if found, otherwise None
"""
try:
assert (x >= 0 and y >= 0 and layer >= 0)
except AssertionError:
raise ValueError
try:
gid = self.layers[int(layer)].data[int(y)][int(x)]
except (IndexError, ValueError):
msg = "Coords: ({0},{1}) in layer {2} is invalid."
logger.debug(msg.format(x, y, layer))
raise Exception
else:
try:
return self.tile_properties[gid]
except (IndexError, ValueError):
msg = "Coords: ({0},{1}) in layer {2} has invalid GID: {3}"
logger.debug(msg.format(x, y, layer, gid))
raise Exception
except KeyError:
return None
Traceback (most recent call last):
File "C:/Users/tett/Documents/Vietnam/test.py", line 16, in <module>
properties = tmxdata.get_tile_properties(x, y, layer)
File "C:\Users\tett\PycharmProjects\untitled\venv\lib\site-
packages\pytmx\pytmx.py", line 568, in get_tile_properties
assert (x >= 0 and y >= 0 and layer >= 0)
TypeError: '>=' not supported between instances of 'TiledTileLayer' and 'int'
I started learning pyGame two weeks before posting this so I know how tiled maps are way above my skill level. because of that, I copied this and some other code off of the pyTMX website. I believe tiled maps is the next most important thing I need to learn for my game before I move on. The code doesn't seem to work (for me at least) and that is why I am on here to see if anybody has a solution. I looked on Youtube, those tiled map tutorial videos didn't work and my solutions to fix this issue didn't work.
The code I copied to call the pyTMX file looks like this. m1w1.tmx is the file I am trying to load.
tmxdata = pytmx.TiledMap("m1w1.tmx")
tiled_map = pytmx.TiledMap('m1w1.tmx')
for layer in tiled_map.layers:
for x, y, image in layer.tiles():
for obj in layer:
# tile ('GID') properties are accessed through the TiledMap:
properties = tmxdata.get_tile_properties(x, y, layer)
bbox = obj.x, obj.y, obj.width, obj.height
points = obj.points
# if obj.closed == True, then obj is a polygon