Apologies if this has been asked, but I searched and did not find anything.
I am attempting to import a tmx file into pygame using pytmx, but when I import I get the following error (I will post full log below if it helps) “Tile bounds outside bounds of tileset image”
I tested by creating a new .tmx file and running the exact same code but on that path, and it opened a window up with no error message, so the issue must be in my specific .tmx file. I don’t know what I might have done wrong, but this map took me hours to make so hopefully I can fix it rather than trying to redo it from scratch!
Full log of error:
Tile bounds outside bounds of tileset image
Traceback (most recent call last):
File "/Users/angelopportunity/Dropbox/My Mac (Michael’s MacBook Pro)/Desktop/RTS/RTS.py", line 7, in <module>
tmx_data = load_pygame(
File "/usr/local/lib/python3.9/site-packages/pytmx/util_pygame.py", line 183, in load_pygame
return pytmx.TiledMap(filename, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/pytmx/pytmx.py", line 501, in __init__
File "/usr/local/lib/python3.9/site-packages/pytmx/pytmx.py", line 573, in parse_xml
File "/usr/local/lib/python3.9/site-packages/pytmx/pytmx.py", line 627, in reload_images
self.images[gid] = loader(rect, flags)
File "/usr/local/lib/python3.9/site-packages/pytmx/util_pygame.py", line 136, in load_image
tile = image.subsurface(rect)
ValueError: subsurface rectangle outside surface area
Could it perhaps be that you’re loading the wrong image or failing to load an image when you load the tileset, so when you ask for a particular subrect of it, it’s not there?
This is possible, how would I try to troubleshoot that? When I loaded the tilesets in on Tiled, everything lined up and worked fine, so I assumed there wasn’t any issue there. Is there some numbers I should be checking within the tileset information? I have several tilesets loaded for his map. Should I check them all one-by-one somehow?
Do you copy/move any files between using them in Tiled and in your game? If not, then if it works in Tiled, then your paths are probably fine.
Presumably Python has some way to check the sizes of the loaded images, so I’d start by printing all of those out and seeing if anything looks off (e.g. is 0x0).
If all the images look fine, then it’s possible you’re trying to get non-existing tiles from the tilesets somehow, i.e. using the library wrong in some way.
I guess the issue I’m having is that I am basically doing nothing so far. All I’ve done is attempted to load the tmx file into a variable. There is no “game” yet or anything else. I get this error just from trying to load the tmx file, so it doesn’t let me print anything either, it just crashes immediately with this error.
EDIT: I will try to go everything one at a time when I get a chance and report back. I am guessing something is messed up with the way I imported the tilesets within Tiled. I’ll try to clean everything up and see if that fixes it.
I tested out a lot of stuff and I found that for whatever reason, there will be no error as long as I ONLY draw tiles from the first row of the tileset. As soon as I draw even one tile from the second or third row, I get the error. This feels to me like it’s some issue within pytmx rather than Tiled. I will try using an earlier version of Python and seeing if that somehow fixes it. Thanks for the help!