Skip to content
Michael Aquilina edited this page May 14, 2013 · 6 revisions

Tiled Overview

TeeEngine offers support for loading and displaying files produced by the Tiled Map Editor. Currently, it supports loading from XML based (.tmx) files stored in CSV format. There is planned support for loading from Base64 encoded data in the future in order to compress the amount of space needed to store tile data within the file (but at the current stage of development it is not a priority). The TiledMap loader also supports loading from externally referenced tileset files (.tsx) that can be shared by multiple maps for maintainable code.

Tiled Properties

All classes found in the Tiled namespace inherit from the PropertyBag class which provides methods for setting/getting properties that would have been specified in Tiled. In Tiled, every object, tile, tileset, map etc... can have a limitless amount of key/value pair properties specified. This allows for metadata about the game that isn't directly supported by Tiled, to be specified and parsed by the game's code. Each class within the Tiled namespace supports the following methods:

  • GetProperty(string name, string defaultValue=Null): Gets the specified property as a string value. If the property does not exist, the specified defaultValue will be returned.

  • GetProperty(string name, T defaultValue): Get the specified Property 'Name' and Convert it to the type T (e.g. float, int, double etc...). If the Property does not exist, the Default value specified will be returned.

  • SetProperty(string name, string value): Sets the specified property to the specified value.

  • LoadProperties(XmlNode selectedNode): mainly an internal function. Loads the properties in an XmlNode that would have been saved by the Tiled Map Editor.

Requirements

In order to load textures used in a TiledMap file, the TeeEngine needs to know what content each tileset is associated with in the Content Pipeline. For this reason, in order to load TiledMap files - each tileset used in a TiledMap must also specify the property 'Content' which specifies the named path of the texture content to be loaded for that tileset.

If a Map Script is going to be used in a Tiled Map, then the Assembly in which to find the Map Script and the full name of the class that will act as the MapScript needs to be specified in the Map's properties.

Loading a TiledMap

Loading a TiledMap can be done very easily using either the static method TiledMap.FromXML() or alternatively, from the TeeEngine method LoadMap(). Loading a map with the TeeEngine method will immediately load it into the current engine instance for viewing, while the static TiledMap method will not.

TeeEngine is capable of automatically detecting and converting objects specified in the TiledMap to Entity objects. (STUB)

Tiled Classes

TiledMap

The Main class that represents a map created by the Tiled Map Editor. The most common way to initialise a TiledMap is to load it from a .tmx file using the static class method FromTiledXml(). A TiledMap class instance contains the following properties:

  • txWidth: The width of the Map in terms of the number of tiles.
  • txHeight: The height of the Map in terms of the numbre of tiles.
  • pxWidth: The width of the Map in terms of pixels.
  • pxHeight: The height of the Map in terms of pixels.
  • TileWidth: The standard width of each tile used in the Map in pixels.
  • TileHeight: The standard height of each tile used in the Map in pixels.
  • Background: The background Color used in the Map. In the case where a tile does not exist at some coordinate. This background Color would show.
  • Tiles: A SortedList of tiles used in the Map. The list is organised by each Tile's TileGid property.
  • TileLayers: A List of TileLayer objects used by the Map. Each TileLayer contains an array of tile gids which specify the actual layout and format of the map.
  • TiledObjectLayers: A List of TiledObjectLayer objects used by the Map. each TiledObjectLayer contains a reference to a List of a number of TiledObjects.
  • TileSets: A List of TileSet objects which are used by the Map. Each tileset contains a reference to a List of relevant Tile objects as well as other relevant metadata. Each tile stored in the TileSet is stored in a SortedList organised by the Tile's local TileId proprety.

Tile

Represents a single Tile that can be used within the TiledMap. The object contains properties that expose both its local id within the TileSet containing it and its global id within the TiledMap it is used in. The Tile class provides a useful helper method to quickly convert itself into a StaticImage using the ToStaticImage() method (See an example of its use in TeeEngine.ConvertMapObjects)

The Tile also has a direct reference to its parent TileSet for convenience purposes. This reference is bi-directional since the TileSet instance should also refer to the Tile in its Tiles property.

TileLayer

Represents a single layer on the map which contains Tile information to be drawn. Each TileLayer instance contains the actual layout data that determines what is drawn to screen by maintaining a list of global tile ids.

TileSet

TiledObject