├── .gitignore
├── LICENSE
├── README.md
├── as3-tiled-reader.iml
├── bin
└── as3-tiled-reader.swc
└── src
└── io
└── arkeus
└── tiled
├── TiledImage.as
├── TiledImageLayer.as
├── TiledLayer.as
├── TiledLayers.as
├── TiledMap.as
├── TiledObject.as
├── TiledObjectLayer.as
├── TiledProperties.as
├── TiledReader.as
├── TiledTerrain.as
├── TiledTile.as
├── TiledTileLayer.as
├── TiledTileset.as
├── TiledTilesets.as
├── TiledUtils.as
└── base64
└── Base64.as
/.gitignore:
--------------------------------------------------------------------------------
1 | html-template
2 | bin-debug
3 | bin-release
4 | www
5 | air
6 | docs
7 | .settings
8 | .actionScriptProperties
9 | .project
10 | .git
11 | org
12 | adobe
13 | *.psd
14 | Thumbs.db
15 | .DS_Store
16 | .flexLibProperties
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2013 Lee Miller
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AS3 Tiled Reader
2 | ====
3 |
4 | About
5 | -----
6 |
7 | Tiled Reader is an as3 tmx parser allowing you to read maps exported via the [Tiled Map Editor](http://www.mapeditor.org/ "Tiled Map Editor"). Tiled Reader was created to allow you to easily save your Tiled maps using the default format and load them in flash games.
8 |
9 | Features
10 | --------
11 |
12 | Tiled Reader allows you to load maps that are compressed using zlib and encoded using base64. It takes advantage of the native flash zlib compression, and uses a very fast open source base64 library to decode your layer data.
13 |
14 | Tiled Reader supports all major features of Tiled 0.9.0, including tile layers, object layers, image layers, properties, and terrain.
15 |
16 | How To Use
17 | ----------
18 |
19 | Using Tiled Reader is easy. You either either embed a TMX file directly into your application, or parse an XML object direct.
20 |
21 | If you choose to use an embedded file, embed the map as follows:
22 |
23 | [Embed(source = "/map/world.tmx", mimeType = "application/octet-stream")] public static const WORLD:Class;
24 |
25 | You can then load, and parse the map file as follows:
26 |
27 | var reader:TiledReader = new TiledReader;
28 | var map:TiledMap = reader.loadFromEmbedded(WORLD);
29 |
30 | If you want to use an actual XML object, load the XML using any method you'd like (internally or externally), and simple use the loadFromXML function on TiledReader.
31 |
32 | After loading the file, you can access layers, properties, and more from the returned TiledMap. Check out the TiledMap.as file's documentation for all attributes and functions.
33 |
34 | Example
35 | -------
36 |
37 | To see an example of Tiled Reader being used, check out the [Axelite Moon](https://github.com/arkeus/axelite-moon "Axelite Moon") project.
38 |
39 | Support
40 | -------
41 |
42 | If you find a bug, or notice that a feature isn't support, feel free to open an issue against the project!
--------------------------------------------------------------------------------
/as3-tiled-reader.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/bin/as3-tiled-reader.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arkeus/as3-tiled-reader/bba566c4619d5ca34c097d2850656af26243017d/bin/as3-tiled-reader.swc
--------------------------------------------------------------------------------
/src/io/arkeus/tiled/TiledImage.as:
--------------------------------------------------------------------------------
1 | package io.arkeus.tiled {
2 | /**
3 | * Represents an image within a tiled map. The source is a string containing the path
4 | * to the image relative to the location of the map.
5 | */
6 | public class TiledImage {
7 | /** The string containing the path to the image relative to the map file. */
8 | public var source:String;
9 | /** The width of the image. */
10 | public var width:uint;
11 | /** The height of the image. */
12 | public var height:uint;
13 | /** The transparent color, -1 if no transparent color. */
14 | public var transparentColor:int;
15 |
16 | /**
17 | * @param tmx The XMLList containing the object.
18 | */
19 | public function TiledImage(tmx:XMLList) {
20 | source = tmx.@source;
21 | width = tmx.@width;
22 | height = tmx.@height;
23 | transparentColor = "@trans" in tmx ? TiledUtils.colorStringToUint(tmx.@trans) : -1;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/io/arkeus/tiled/TiledImageLayer.as:
--------------------------------------------------------------------------------
1 | package io.arkeus.tiled {
2 | /**
3 | * A class representing an layer. In addition to the base layer properties,
4 | * an image layer contains a single image.
5 | */
6 | public class TiledImageLayer extends TiledLayer {
7 | /** The layer's image. */
8 | public var image:TiledImage;
9 |
10 | /**
11 | * @param tmx The XML containing the object.
12 | */
13 | public function TiledImageLayer(tmx:XML) {
14 | super(tmx);
15 | image = new TiledImage(tmx.image);
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/src/io/arkeus/tiled/TiledLayer.as:
--------------------------------------------------------------------------------
1 | package io.arkeus.tiled {
2 | /**
3 | * Represents a layer in the map. Layers can be one of three types: TiledTileLayer (tile layer),
4 | * TiledImageLayer (image layer), or TiledObjectLayer (object group).
5 | */
6 | public class TiledLayer {
7 | /** The name of the layer. */
8 | public var name:String;
9 | /** The width of the layer. Usually equal to the map width. */
10 | public var width:uint;
11 | /** The height of the layer. Usually equal to the map height. */
12 | public var height:uint;
13 | /** The opacity of the map between 0.0 and 1.0. */
14 | public var opacity:Number;
15 | /** Whether or not this layer is set to be visible or not. */
16 | public var visible:Boolean;
17 | /** Layer properties. */
18 | public var properties:TiledProperties;
19 |
20 | /**
21 | * @param tmx The XML containing the layer object.
22 | */
23 | public function TiledLayer(tmx:XML) {
24 | name = tmx.@name;
25 | width = tmx.@width;
26 | height = tmx.@height;
27 | opacity = "@opacity" in tmx ? tmx.@opacity : 1.0;
28 | visible = !("@visible" in tmx && tmx.@visible == "0");
29 | properties = new TiledProperties(tmx.properties);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/io/arkeus/tiled/TiledLayers.as:
--------------------------------------------------------------------------------
1 | package io.arkeus.tiled {
2 | /**
3 | * A container holding all the layers within the map. Provides utility functions for grabbing
4 | * visible layers, tile layers, and all layers.
5 | */
6 | /**
7 | *
8 | * @author Lee
9 | */
10 | public class TiledLayers {
11 | /** The vector of layers in order from bottom to top. */
12 | public var layers:Vector.;
13 |
14 | public function TiledLayers() {
15 | layers = new Vector.;
16 | }
17 |
18 | /**
19 | * Adds a layer on top of all other layers.
20 | *
21 | * @param layer The layer to add.
22 | */
23 | public function addLayer(layer:TiledLayer):void {
24 | layers.push(layer);
25 | }
26 |
27 | /**
28 | * Returns a vector of all layers in order from bottom to top.
29 | *
30 | * @return The vector of all layers.
31 | */
32 | public function getAllLayers():Vector. {
33 | return layers;
34 | }
35 |
36 | /**
37 | * Returns a vector of all visible layers in order from bottom to top.
38 | *
39 | * @return The vector of all visible layers.
40 | */
41 | public function getVisibleLayers():Vector. {
42 | return layers.filter(function(el:TiledLayer, i:int, arr:Vector.):Boolean { return el.visible; });
43 | }
44 |
45 | /**
46 | * Returns a vector of all tile layers in order from bottom to top.
47 | *
48 | * @return The vector of all tile layers.
49 | */
50 | public function getTileLayers():Vector. {
51 | return layers.filter(function(el:TiledLayer, i:int, arr:Vector.):Boolean { return el is TiledTileLayer; });
52 | }
53 |
54 | /**
55 | * Returns a vector of all object layers in order from bottom to top.
56 | *
57 | * @return The vector of all object layers.
58 | */
59 | public function getObjectLayers():Vector. {
60 | return layers.filter(function(el:TiledLayer, i:int, arr:Vector.):Boolean { return el is TiledObjectLayer; });
61 | }
62 |
63 | /**
64 | * Returns the number of layers in the map.
65 | *
66 | * @return The number of layers.
67 | */
68 | public function get length():uint {
69 | return layers.length;
70 | }
71 |
72 | /**
73 | * Overwrites toString to simple return the number of layers.
74 | */
75 | public function toString():String {
76 | return length + " layers";
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/io/arkeus/tiled/TiledMap.as:
--------------------------------------------------------------------------------
1 | package io.arkeus.tiled {
2 | /**
3 | * A fully parsed tiled map. Contains all information about the map, including the
4 | * parsed layers.
5 | */
6 | public class TiledMap {
7 | /** The TMX format version, always 1.0 currently. */
8 | public var version:String;
9 | /** Map orientation, one of: orthogonal, isometric, stagerred. */
10 | public var orientation:String;
11 | /** The width of the map in tiles. */
12 | public var width:uint;
13 | /** The height of the map in tiles. */
14 | public var height:uint;
15 | /** The width of a tile in pixels. */
16 | public var tileWidth:uint;
17 | /** The height of a tile in pixels. */
18 | public var tileHeight:uint;
19 | /** The background color of the map. */
20 | public var backgroundColor:uint;
21 | /** Properties of the map. */
22 | public var properties:TiledProperties;
23 | /** A container containing information on the tilesets of the map. */
24 | public var tilesets:TiledTilesets;
25 | /** A container containing information on the layers of the map. */
26 | public var layers:TiledLayers;
27 |
28 | public function TiledMap(tmx:XML) {
29 | version = "@version" in tmx ? tmx.@version : "?";
30 | orientation = "@orientation" in tmx ? tmx.@orientation : "othogonal";
31 | width = tmx.@width;
32 | height = tmx.@height;
33 | tileWidth = tmx.@tilewidth;
34 | tileHeight = tmx.@tileheight;
35 | backgroundColor = "@backgroundcolor" in tmx ? TiledUtils.colorStringToUint(tmx.@backgroundcolor) : 0xffffff;
36 | properties = new TiledProperties(tmx.properties);
37 | tilesets = new TiledTilesets(tmx.tileset);
38 | parseLayers(tmx);
39 | }
40 |
41 | /**
42 | * Parses the layers of the map, building the TiledLayers container containing information
43 | * on each parsed layer. The order of the layers is kept intact, from bottom to top.
44 | *
45 | * @param tmx The map object.
46 | */
47 | private function parseLayers(tmx:XML):void {
48 | layers = new TiledLayers;
49 |
50 | // Parse all children, since for some reason layer and objectgroup aren't grouped easily, even though the ordering
51 | // between them can be very important. WHY BJORN, WHY?
52 | var elements:XMLList = tmx.children();
53 | for (var i:uint = 0; i < elements.length(); i++) {
54 | var name:QName = (elements[i] as XML).name() as QName;
55 | if (name.localName == "layer") {
56 | layers.addLayer(new TiledTileLayer(elements[i]));
57 | } else if (name.localName == "objectgroup") {
58 | layers.addLayer(new TiledObjectLayer(elements[i]));
59 | } else if (name.localName == "imagelayer") {
60 | layers.addLayer(new TiledImageLayer(elements[i]));
61 | }
62 | }
63 | }
64 |
65 | /**
66 | * Converts the map to a string containing the main properties for debugging purposes.
67 | *
68 | * @return The map in string format.
69 | */
70 | public function toString():String {
71 | return [
72 | "Version: " + version,
73 | "Orientation: " + orientation,
74 | "Width: " + width,
75 | "Height: " + height,
76 | "TileWidth: " + tileWidth,
77 | "TileHeight: " + tileHeight,
78 | "BackgroundColor: " + backgroundColor,
79 | "Properties: " + properties,
80 | "Tilesets: " + tilesets,
81 | "Layers: " + layers,
82 | ].join(", ");
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/io/arkeus/tiled/TiledObject.as:
--------------------------------------------------------------------------------
1 | package io.arkeus.tiled {
2 | import flash.geom.Point;
3 |
4 | /**
5 | * Represents a single