Tilemaps and .tmx files

291 views
Skip to first unread message

Brandon Jumbeck

unread,
Aug 5, 2013, 2:59:11 PM8/5/13
to pyglet...@googlegroups.com
Does there happen to be a prebuilt library that would work with Pyglet to handle tilemaps made by the Tiled Map Editor? If not any advice on what I would need to do to handle Tiled generated tile map files. I have tried using the Cocos2D library and its tilemap features but that library confuses the hell out of me and can't seem to get it to work.

For creating one I believe all all I would need to do is create a way to parse the information from the .tmx map files and then create a collision manager base around that information on the .tmx files? Though I could be wrong because I have never really dealt to much with tile maps and collision in general.

So any help of information would be great and thanks in advance for taking the time to help me :).

Petr Viktorin

unread,
Aug 5, 2013, 3:14:31 PM8/5/13
to pyglet-users
On Mon, Aug 5, 2013 at 8:59 PM, Brandon Jumbeck <bjum...@gmail.com> wrote:
> Does there happen to be a prebuilt library that would work with Pyglet to
> handle tilemaps made by the Tiled Map Editor? If not any advice on what I
> would need to do to handle Tiled generated tile map files. I have tried
> using the Cocos2D library and its tilemap features but that library confuses
> the hell out of me and can't seem to get it to work.

What exactly do you mean by "handle"?
The Tiled wiki has a section on TMX libraries for Python. Try if one
works for you: https://github.com/bjorn/tiled/wiki/Support-for-TMX-maps#pythonpygame.

> For creating one I believe all all I would need to do is create a way to
> parse the information from the .tmx map files and then create a collision
> manager base around that information on the .tmx files? Though I could be
> wrong because I have never really dealt to much with tile maps and collision
> in general.

It all depends on what exactly you want to do with the map, and how
(for example) collision info is stored in your map.

Fred

unread,
Aug 5, 2013, 3:31:08 PM8/5/13
to pyglet...@googlegroups.com
tmx files are only xml. Any xml parser will do. For example, xml.etree.ElementTree (from the standard library) is sufficient (that's what I use). Of course, you'll have to code your own renderer.

The collision map is usually handled as an invisible layer in the tmx file.

Brandon Jumbeck

unread,
Aug 5, 2013, 3:58:31 PM8/5/13
to pyglet...@googlegroups.com
What exactly do you mean by "handle"?
The Tiled wiki has a section on TMX libraries for Python. Try if one
works for you: https://github.com/bjorn/tiled/wiki/Support-for-TMX-maps#pythonpygame. 

Sorry about that when I said handle I should have said I would like it to be able to render the tilemap along with being able to determine each cells properties(Whether the properties come from the tile on that cells, the cell itself, or even a map wide property) and store them so they can be used to determine collision in the game.

Thank you also for the link will take a look at those when I am off work and see if any of them work. Or can be modified away from pygame.

Thank you for the links they have helped a lot.

The collision map is usually handled as an invisible layer in the tmx file.

Hmm I am not sure I get what you mean by invisible layer in the tmx file. Could you explain this a bit more please?  


Fred

unread,
Aug 5, 2013, 5:24:40 PM8/5/13
to pyglet...@googlegroups.com


On Monday, August 5, 2013 9:58:31 PM UTC+2, Brandon Jumbeck wrote:
The collision map is usually handled as an invisible layer in the tmx file.

Hmm I am not sure I get what you mean by invisible layer in the tmx file. Could you explain this a bit more please?  

You create a layer with your map editor (I use tiled), you use a set of W&B tiles for the collision mask and you set your layer invisible. It appears this way in the tmx :

<layer name="collisions" visible="0" width="180" height="120">
  <data encoding="base64" compression="zlib">
   ...
  </data>
 </layer>
 
Of course, you have to code your own routine to check collision. Personnally, I used numpy.arrays of boolean for representing each "collision_tile". I wrote a function collision(collision_layer, collision_tiles, x, y) to check if the bit at position (x, y) on the layer is masked or not, then I test only the pixels on the edge of the object I want to test. It was fast enough on my first attempt, but my second being more ambitious, I'll use numpy abilities to work on entire array.
Reply all
Reply to author
Forward
0 new messages