This module provides support for loading the Tiled TMX format. This allows you to use Tiled
to edit your game’s world (e.g. levels), rather than building a level
editor yourself.
To load a TMX map, simply use xsge.tmx.load(). See the
documentation for this function for more information.
-
class xsge.tmx.Decoration(x, y, z=0, sprite=None, visible=True, active=False, checks_collisions=False, tangible=False, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, xacceleration=0, yacceleration=0, xdeceleration=0, ydeceleration=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Default class for tiles and image layers. Identical to
sge.Object, except that it is intangible and doesn’t check
for collisions by default.
-
class xsge.tmx.Rectangle(x, y, z=0, sprite=None, visible=False, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, xacceleration=0, yacceleration=0, xdeceleration=0, ydeceleration=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Default class for rectangle objects. Identical to
sge.Object, except that it is invisible by default.
-
class xsge.tmx.Ellipse(x, y, z=0, sprite=None, visible=True, active=True, checks_collisions=True, tangible=True, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=True, collision_precise=False, xvelocity=0, yvelocity=0, xacceleration=0, yacceleration=0, xdeceleration=0, ydeceleration=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Default class for ellipse objects. Identical to
sge.Object, except that it is invisible and uses ellipse
collision detection by default.
-
class xsge.tmx.Polygon(x, y, points=(), z=0, sprite=None, visible=False, active=True, checks_collisions=False, tangible=False, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, xacceleration=0, yacceleration=0, xdeceleration=0, ydeceleration=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Default class for polygon objects. Identical to
xsge.path.Path.
-
class xsge.tmx.Polyline(x, y, points=(), z=0, sprite=None, visible=False, active=True, checks_collisions=False, tangible=False, bbox_x=None, bbox_y=None, bbox_width=None, bbox_height=None, regulate_origin=False, collision_ellipse=False, collision_precise=False, xvelocity=0, yvelocity=0, xacceleration=0, yacceleration=0, xdeceleration=0, ydeceleration=0, image_index=0, image_origin_x=None, image_origin_y=None, image_fps=None, image_xscale=1, image_yscale=1, image_rotation=0, image_alpha=255, image_blend=None)[source]
Default class for polyline objects. Identical to
xsge.path.Path.
-
xsge.tmx.load(fname, cls=<class 'sge.Room.Room'>, types=None, z=0)[source]
Load the TMX file fname and return a room of the class cls.
The way the map generates the room, in general, is to convert all
tiles, objects, and image layers into sge.Object objects.
As a special exception, the object layer with the name “views”
defines the views in the room; these objects are converted into
sge.View objects.
Objects are given Z-axis positions based on the ordering of the
layers in the TMX file: z is the Z-axis position of the first
layer, and each subsequent layer’s Z-axis position is the Z-axis
position of the previous layer plus one.
Except for views, all tiles, objects, and image layers can be
defined to be converted into any class derived from
sge.Object via the types argument, which should be a
dictionary matching strings to corresponding sge.Object
classes, or None, which is equivalent to {}. Classes
are determined in the following ways:
- Tiles are converted to the class connected to, in order of
preference, the name of the tileset or the name of the tile layer.
If neither of these strings are valid keys in types,
xsge.tmx.Decoration is used.
- Objects are converted to the class connected to, in order of
preference, the name of the object, the type of the object, or the
name of the object group. If none of these strings are valid keys
in types, the class used depends on what kind of object it is:
- Image layers are converted to the class connected to the image
layer’s name. If the image layer’s name is not a valid key in
types, xsge.tmx.Decoration is used.
Property lists, converted to integers or floats if possible, are
passed to objects as keyword arguments in the following ways:
- Tiles have their properties, the properties of their tilesets, and
the properties of their layers applied to them. Tileset properties
override layer properties, and tile properties override tileset
properties.
- Tile objects have their properties, the properties of their tiles,
the properties of their tiles’ tilesets, and the properties of
their object groups applied to them. Object properties override
tile properties, tile properties override tileset properties, and
tileset properties override object group properties.
- Other objects have their properties and the properties of their
object groups applied to them. Object properties override object
group properties.
- Image layers have their properties applied to them.