Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Tiled map importing into PyGame
#1
I am trying to create a 2D puzzle platformer, using Tiled as the map creation tool.

All I want to figure out is how to import a map made in Tiled, and then how to set each tile to an object (ex: a wall, enemy, the player, a powerup etc.)

I have been following this tutorial for movement
I got to the point where I had a moving cube that could jump and not walk off of the screen. I then learned on my own how to import an image and make it the cube instead of a colored rectangle.

I then made my own tileset, and used it in Tiled to create the level I wanted. I put in walls, a player, and an enemy.

Afterwards I found this tutorial, which I am now trying to piece together how it imports the map and its various layers using the module pytmx in conjunction with pygame.

Does anyone here know the best way to go about this?
Quote
#2
I dont remember the process to be honest. I havent done it in about 5 years now (wow has it been that long Shocked ). There is only 3 people i know of on this forum that has used Tiled/pytmx to load tilesets. You might find more people (or currently using) pytmx on pygame reddit. The author of pytmx also hangs out a lot in that subreddit; bitcraft.
If you go to his github pytmx repo he has a table of content for instructions on how to use various features.

I am not sure if this would help or not, but this was my little test of pygame/pytmx/ using Tiled to create the level. One color was in the grass and another identified it as collision for simplicity. This should at least give an example of importing pytmx and basic usage. However i like to limit the amount of installations the user has to do, so i included pytmx with packages...not make the user install it. The renderer.Renderer class is where i think might instruct a basic usage and its usage in level.py to identify blockers as that is the majority relating to loading the tileset and pytmx usage.
https://github.com/metulburr/rpg_test

Sorry i could not help more. I just dont remember the process. But this is what i would research, if i wanted to do it again. I hope i gave enough information for you to take a whack at it.
Quote
#3
First of all, thank you so much for your help, means a lot. I will definitely check out those subreddits, but I tried running your code using

python3 main.py

and got this error

Error:
pygame 1.9.4 Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last): File "main.py", line 4, in <module> import level File "/media/nodding/F79C-1E18/Python Programs/rpg_test-master/rpg_test-master/level.py", line 1, in <module> import renderer File "/media/nodding/F79C-1E18/Python Programs/rpg_test-master/rpg_test-master/renderer.py", line 1, in <module> import pytmx File "/media/nodding/F79C-1E18/Python Programs/rpg_test-master/rpg_test-master/pytmx/__init__.py", line 2, in <module> from tmxloader import load_pygame, load_tmx ImportError: No module named 'tmxloader'
I tried downloading a module named "tmxloader" like it was saying, but it did not say there was one.

Any idea as to what this means?
Quote
#4
Try python 2.x. pytmx might not have been compatible with 3.x back then. In the meantime i will try to update that repo with the latest pytmx to be p3 compatible.

EDIT:
apparently he made a bunch of name changes. I made an issue asking for help with some of the conversion because i havent been in the loop in a long time. So this will change slightly with usage. So its probably not a good idea just to use python2.x because the methods have changed since then. Im currently stumped on what he changed tmx.GetObjects to, but i think that is the last name change i have done on my local repo. Sorry, my example wasnt suppose to be dead in the water. I also didnt know he changed names of methods either. He always answers at some point. But not sure how long it will take.
https://github.com/bitcraft/PyTMX/issues/114
Quote
#5
@metulburr
Going through source code. Under TiledMap. It looks like they are properties now.
PyTMX Line 721 objectgroups and line 729 objects.
99 percent of computer problems exists between chair and keyboard.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PyGame] Problem importing pygame / installing pygame Klar 4 1,935 Dec-16-2017, 05:48 PM
Last Post: Klar
  Importing pygame Mac problem Benjipincus 1 674 Dec-16-2017, 01:54 PM
Last Post: metulburr
  [Pygame] Avoid SentDex pygame tutorials georgecoopers 1 1,469 Apr-09-2017, 12:40 PM
Last Post: metulburr

Forum Jump:


Users browsing this thread: 1 Guest(s)