Working with tmx files in pygame

Working with tmx files in pygame

Postby Zero » Tue Oct 29, 2013 11:45 am

Hi, i'm currently making a game which involves the use of Richard Jones' tmx.py to load my tilemaps that i made in Tiled. i used the code 14-tilemap.py from his pygame tutorial https://bitbucket.org/r1chardj0n3s/pyga ... at=default with my own tile/tileset and map, named 'tiles' and 'map' respectively.
Whenever i run the program (using Stani's python editor), i always get " KeyError: 'triggers' " and refers to line 384 in tmx.py. i understand that 'triggers' is the name of an object layer in the map.tmx file but when i run 14-tilemap.py with the files provided in the link above it runs without a problem. Im fairly new to pygame and i don't know how to tackle this, Is there anyway i can load/blit my map onto a pygame window without any errors?

P.S i also noticed that 14-tilemap.py wont run without 'tiles.tsx' and 'triggers.tsx', does this link to this problem in any way?
Last edited by stranac on Tue Oct 29, 2013 12:25 pm, edited 1 time in total.
Reason: First post lock.
Zero
 
Posts: 6
Joined: Tue Oct 29, 2013 11:12 am

Re: Working with tmx files in pygame

Postby dboxall123 » Tue Oct 29, 2013 1:45 pm

I think that I've had this problem before. Post the full traceback.
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Working with tmx files in pygame

Postby Zero » Tue Oct 29, 2013 9:14 pm

here's the traceback
Attachments
traceback.png
traceback.png (30.64 KiB) Viewed 1075 times
Zero
 
Posts: 6
Joined: Tue Oct 29, 2013 11:12 am

Re: Working with tmx files in pygame

Postby dboxall123 » Tue Oct 29, 2013 9:48 pm

Well, the problem here is that there is no layer in your map named 'triggers'. In Tiled, did you accidently save the layer that you're referring to with a capital letter, or misspell it?
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Working with tmx files in pygame

Postby Zero » Wed Oct 30, 2013 7:21 am

I didn't mispell it or use capital letters, i made sure of that. When i load Richard Jones' original map, it works perfectly although there's no object layer called 'triggers' (but there's a tile layer called 'triggers') but my map has an object layer called 'triggers' and it still won't run.
Zero
 
Posts: 6
Joined: Tue Oct 29, 2013 11:12 am

Re: Working with tmx files in pygame

Postby dboxall123 » Wed Oct 30, 2013 9:32 am

Hmmm. Right, this is almost certainly a problem with the tmx file, upload it so I can have a look. Also include your code.
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Working with tmx files in pygame

Postby Zero » Wed Oct 30, 2013 10:58 am

Here's the code and the files in it's directory http://www.mediafire.com/download/yhxaskhno6of4x6/tmx_load_test.zip.
You might want to delete the tsx files, i dunno if they affect the code in any way but it's some i want you to note.
Zero
 
Posts: 6
Joined: Tue Oct 29, 2013 11:12 am

Re: Working with tmx files in pygame

Postby dboxall123 » Wed Oct 30, 2013 6:02 pm

Hmm, this is quite a strange one. I have personally never had any luck using object layers. I had lot's of problems trying to do so. In the end, I didn't even bother with object layers, I decided to just use tile layers, as you can acheive the same thing. Sorry I couldn't be of more help.
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Working with tmx files in pygame

Postby Zero » Wed Oct 30, 2013 6:11 pm

Thanks for trying. Also, if it isn't any trouble, could you give me a small tutorial on how you would use tile layers instead? as you said you can achieve the same thing
Zero
 
Posts: 6
Joined: Tue Oct 29, 2013 11:12 am

Re: Working with tmx files in pygame

Postby dboxall123 » Wed Oct 30, 2013 7:41 pm

Sure, I will make a short tutorial. You'll have to give me a bit of time though, it's been a while since I used Tiled.
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Working with tmx files in pygame

Postby Zero » Sun Mar 23, 2014 10:22 am

Thanks for your help, i managed the tmx loader to work. by the way, i have quick question regarding the actuall maps themselves, Is it possible to load maps from a sub directory when the main file you're loading to is in the parent directory?
Also, Sorry for taking long to reply :P
Zero
 
Posts: 6
Joined: Tue Oct 29, 2013 11:12 am


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron