HaxePunk / tiled

Tiled TMX import for HaxePunk
50 stars 18 forks source link
haxepunk tiled

Build Status

HaxePunk Tiled

Add the HaxePunk Tiled library to your game

You need to add

<haxelib name="HaxePunkTmx" />

to your project.xml file.

Add your maps to project.xml

<assets path="assets/maps" rename="maps" include="*.tmx" />

Load a map layers and collision

To use this as a background image simply create a new instance of TmxEntity.

import haxepunk.tmx.TmxEntity;

public function createMap()
{
  // create the map
  var e = new TmxEntity("maps/mylevel.tmx");

  // load layers named bottom, main, top with the appropriate tileset
  e.loadGraphic("graphics/tileset.png", ["bottom", "main", "top"]);

  // loads a grid layer named collision and sets the entity type to walls
  e.loadMask("collision", "walls");

  add(e);
}

Access properties and objects

To access map properties and object layers create an instance of TmxMap. To add it to the scene simply pass the TmxMap object to the TmxEntity constructor.

import haxepunk.tmx.TmxEntity;
import haxepunk.tmx.TmxMap;

public function createMap()
{
    // create the map
    var map = TmxMap.loadFromFile("maps/mylevel.tmx");

    // access map properties
    var prop = map.properties.resolve("myCustomProperties");

    // go through the list of objects in an object layer
    for(object in map.getObjectGroup("myObjectsLayer").objects)
    {
        // you can access:
        object.name;
        object.type;

        object.x;
        object.y;

        object.width;
        object.height;

        // to read custom properties
        object.custom.resolve("myProp");
    }

    // create the map
    var e = new TmxEntity(map);

    // load layers named bottom, main, top with the appropriate tileset
    e.loadGraphic("graphics/tileset.png", ["bottom", "main", "top"]);

    // loads a grid layer named collision and sets the entity type to walls
    e.loadMask("collision", "walls");

    add(e);
}

MIT License

Copyright (C) 2012-2018 HaxePunk contributors (original by Thomas Jahn)

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.