Difference between revisions of "Drawing a Tiled Map"
(→Install PyTMX) |
(→Required) |
||
Line 6: | Line 6: | ||
==Required== | ==Required== | ||
You will need a TMX map, and also the tileset file used and referenced in the map. | You will need a TMX map, and also the tileset file used and referenced in the map. | ||
+ | |||
+ | ==Import PyTMX== | ||
+ | We need to import PyTMX, you need to add the following lines to the start of your code: | ||
+ | |||
+ | <syntaxhighlight lang=python> | ||
+ | import pytmx | ||
+ | from pytmx.util_pygame import load_pygame | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | load_pygame is a method used to load in the map and tileset. | ||
+ | |||
+ | ==Read in Map== | ||
+ | Make sure your map is within the same folder as your code, and that your tileset image is also in the same folder. | ||
+ | |||
+ | <syntaxhighlight lang=python> | ||
+ | tiled_map = load_pygame('test.tmx') | ||
+ | tilewidth = tiled_map.tilewidth | ||
+ | tileheight = tiled_map.tileheight | ||
+ | </syntaxhighlight> |
Revision as of 10:30, 26 March 2018
Install PyTMX
The current version of writing this is 3.21.5, you need to select Tools, Python, Python Environments.
Select Packages and search for PyTMX, this page will show you how to use PyTMX. Other TMX solutions exist and i will overtime have a look to see which are the best.
Required
You will need a TMX map, and also the tileset file used and referenced in the map.
Import PyTMX
We need to import PyTMX, you need to add the following lines to the start of your code:
import pytmx
from pytmx.util_pygame import load_pygame
load_pygame is a method used to load in the map and tileset.
Read in Map
Make sure your map is within the same folder as your code, and that your tileset image is also in the same folder.
tiled_map = load_pygame('test.tmx')
tilewidth = tiled_map.tilewidth
tileheight = tiled_map.tileheight