Pyxel Edit map importer for Haxe

Posted by (twitter: @caribouloche)
April 26th, 2014 1:47 am

If you’re using the awesome pixel editor Pyxel Edit (free version) and you happen to be a haxe user, you can probably use my importer.

https://github.com/Dvergar/PyxelEdit-Map-Importer

This is a really simple project but this is still time you can save for something else. You can basically retrieve a tile array of each layer and this is framework agnostic; but if you’re using openFL, i made a helper.

Here is an example on how to retrieve datas for three layers named “background”, “walls” and “objects” in Pyxel Edit and draw them on screen:

import flash.display.Sprite;
import openfl.Assets;

import pmi.PyxelMapImporter;
import pmi.OpenflHelper;

class Main extends Sprite
{
    public function new()
    {
        super();
        var pyxelMap = new PyxelMapImporter(Assets.getText("assets/map.xml"));
        var background = pyxelMap.getDatasFromLayer("background");
        var walls = pyxelMap.getDatasFromLayer("walls");
        var objects = pyxelMap.getDatasFromLayer("objects");
        var tilemapBackground = OpenflHelper.getTilesheetArray(background);
        var tilemapWalls = OpenflHelper.getTilesheetArray(walls);
        var tilemapObjects = OpenflHelper.getTilesheetArray(objects);
        var tilesheet = OpenflHelper.getTilesheet("assets/map.png");

        tilesheet.drawTiles(flash.Lib.current.graphics, tilemapBackground);
        tilesheet.drawTiles(flash.Lib.current.graphics, tilemapWalls);
        tilesheet.drawTiles(flash.Lib.current.graphics, tilemapObjects);
    }
}

Leave a Reply

You must be logged in to post a comment.

[cache: storing page]