TileMap loader for python for Tiled, a generic tile map editor from http://mapeditor.org/ . It loads the *.tmx files produced by Tiled.
TileMap loader for python for Tiled, a generic tile map editor from http://mapeditor.org/ . It loads the *.tmx files produced by Tiled.
This is the code that helps using the tmx files using pygame. In this module there is a pygame specific loader and renderer.
TODO: mini example and usage of the classes from this module TODO: link to homepage TODO: examples
Bases: object
A renderer for pygame. Should be fast enough for most purposes.
Example:
# init
sprite_layers = get_layers_from_map(resources)
renderer = RendererPygame()
# in main loop
while running:
# move camera
renderer.set_camera_position(x, y)
# draw layers
for sprite_layer in sprite_layers:
renderer.render_layer(screen, sprite_layer, clip_sprites)
Returns the world coordinates for the given screen location and layer.
Note : | this is important so one can check which entity is there in the model (knowing which sprite is there does not help much) |
---|---|
Parameters : |
|
Returns : | Tuple of world coordinates: (world_x, world_y) |
Returns the sprite at the given screen position or None regardless of the layers visibility.
Note : | This does not work wir object group layers. |
---|---|
Parameters : |
|
Returns : | None if there is no sprite or the sprite (SpriteLayer.Sprite instance). |
Returns the sprites at the given screen positions or an empty list. The sprites are the same order as in the layers.sprites list.
Note : | This does not work wir object group layers. |
---|---|
Parameters : |
|
Returns : | A list of sprites or an empty list. |
Renders a layer onto the given surface.
Parameters : |
|
---|
Set the margin around the camera (in pixels).
Parameters : |
|
---|
Set the camera position in the world.
Parameters : |
|
---|
Set the camera position and size in the world.
Parameters : |
|
---|
Bases: tiledtmxloader.tiledtmxloader.AbstractResourceLoader
Resource loader for pygame. Loads the images as pygame.Surfaces and saves them in the variable indexed_tiles.
Example:
res_loader = ResourceLoaderPygame()
# tile_map loaded the the TileMapParser.parse() method
res_loader.load(tile_map)
Bases: object
The SpriteLayer class. This class is used by the RendererPygame.
Bases: object
The Sprite class used by the SpriteLayer class and the RendererPygame.
Add dynamic sprite to this layer.
Parameters : |
|
---|
Add multiple dynamic sprites to this layer.
Parameters : |
|
---|
Makes 1 tile out of 4. The idea behind is that fewer tiles are faster to render, but that is not always true. Grouping them together into one bigger sprite is one way to get fewer sprites.
Not : | This only works for static layers without any dynamic sprites. |
---|---|
Note : | use with caution |
Parameters : |
|
Returns: | new SpriteLayer with fewer sprites but double the size. |
Check if the given sprites is already in this layer.
Parameters : |
|
---|---|
Returns : | bool, true if sprite is in this layer |
Retrieve the current x paralax factor.
Returns : | returns the current x paralax factor. |
---|
Retrieve the current y paralax factor.
Returns : | returns the current y paralax factor. |
---|
Checks if this layer has dynamic sprites at all.
Returns : | bool, true if it contains at least 1 dynamic sprite. |
---|
Merges multiple Sprite layers into one. Only SpriteLayers are supported. All layers need to be equal in tile size, number of tiles and layer position. Otherwise a SpriteLayerNotCompatibleError is raised.
Parameters : |
|
---|---|
Returns: | new SpriteLayer with merged tiles |
Removes a dynamic sprite from this layer.
Parameters : |
|
---|
Remove multiple sprites at once.
Parameters : |
|
---|
Scales a layer and returns a new, scaled SpriteLayer.
Parameters : |
|
---|
Set the paralax factor. This is for paralax scrolling this layer. Values x < 0.0 will make the layer scroll in opposite direction Value x == 0.0 makes the layer fix to the screen (wont scroll) Values 0.0 < x < 1.0 will make scroll the layer slower. Value x == 1.0 is default and make scroll the layer normal. Values x > 1.0 make scroll the layer faster than normal
Parameters : |
|
---|
Bases: exceptions.Exception
Creates one SpriteLayer from index out of the map.
Parameters : |
|
---|---|
Returns : | a SpriteLayer instance |
> Overview This program contains a sample implementation for loading a map produced by Tiled in pyglet. The script can be run on its own to demonstrate its capabilities, or the script can be imported to use its functionality. Users will hopefully use the ResourceLoaderPyglet already provided in this. Tiled may be found at http://mapeditor.org/
> Demo Controls Holding the arrow keys scrolls the map. Holding the left shift key makes you scroll faster. Pressing the Esc key closes the program.
> Demo Features The map is fully viewable by scrolling. You can scroll outside of the bounds of the map. All visible layers are loaded and displayed. Transparency is supported. (Nothing needed to be done for this.) Minimal OpenGL used. (Less of a learning curve.)
Bases: tiledtmxloader.tiledtmxloader.AbstractResourceLoader
Loads all tile images and lays them out on a grid.
Unlike the AbstractResourceLoader this class derives from, no overridden methods use a colorkey parameter. A colorkey is only useful for pygame. This loader adds its own pyglet-specific parameter to deal with pyglet.image.load’s capability to work with file-like objects.
TileMap loader for python for Tiled, a generic tile map editor from http://mapeditor.org/ . It loads the *.tmx files produced by Tiled.
Bases: object
Abstract base class for the resource loader.
Bases: object
A single object on the map.
Ivariables : |
|
---|
Bases: object
Group of objects on the map.
Ivariables : |
|
---|
Bases: object
A single tile.
Ivariables : |
|
---|
Bases: object
An image of a tile or just an image.
Ivariables : |
|
---|
Bases: object
A layer of the world.
Ivariables : |
|
---|
Bases: object
The TileMap holds all the map data.
Ivariables : |
|
---|
Bases: object
Allows to parse and decode map files for ‘Tiled’, a open source map editor written in java. It can be found here: http://mapeditor.org/
Bases: object
A tileset holds the tiles and its images.
Ivariables : |
|
---|
Decodes a base64 string and returns it.
Parameters : |
|
---|---|
Returns: | decoded string |
Uncompresses a gzip string and returns it.
Parameters : |
|
---|---|
Returns: | uncompressed string |