PyMunkTMX
What follows is a brief explanation of the project. Please see the docs at pymunktmx.readthedocs.org for more complete information. Alternatively, you can clone and build the docs locally by using one of the build scripts in the docs directory.
PyMunkTMX is an extension library for PyTMX that allows you to draw pymunk shapes in Tiled object layers and easily load them into your game.
The main, and most useful function from PyMunkTMX is pymunktmx.load_shapes. Use load_shapes to populate a pymunk.Space instance with properly configured objects from a TMX map.
Installation
PyMunkTMX is registered on pypi and can be installed with pip. Alternatively you can clone this repository. Just be sure to add PyMunkTMX to your PYTHONPATH.
Dependencies
- pytmx Is required. It can be found on pypi and installed with pip or cloned from github.
- pymunk Is required. It can be found on pypi and installed with pip or cloned from github.
Generic Example
from pytmx.tmxloader import load_tmx
from pymunk import Space
from pymunktmx import load_shapes
# Load the map data with pytmx
tiled_map = load_tmx("some/path/to/the/map.tmx")
# Create a pymunk Space instance
my_space = Space()
# Read all of the shapes from the tiled_map into the Space instance
load_shapes(tiled_map, space=my_space)
PyGame Example
import pygame
from pytmx.tmxloader import load_pygame
from pymunk import Space
from pymunk.pygame_util import draw
from pymunktmx import load_shapes
# initialize pygame
pygame.init()
screen = pygame.set_mode((640, 480))
# Load the map data with pytmx (note that pygame's display must be
# loaded before calling load_pygame)
tiled_map = load_pygame("some/path/to/the/map.tmx")
# Create a pymunk Space instance
my_space = Space()
# Read all of the shapes from the tiled_map into the Space instance
load_shapes(tiled_map, space=my_space)
# Draw all of the shapes to the pygame display surface and show them
draw(screen, my_space)
pygame.display.flip()
# Loop until smoke
while pygame.QUIT not in [e.type for e in pygame.event.get()]:
pass