Where do we find the API?

mfaulisemfaulise Posts: 4
edited January 2014 in Questions
Hi,

Are there any APIs for Pyxel?  I notice it is built in Flash, does that mean there are Actionscript libraries available to load maps in game?  If so, how would I find them?

Thanks,
--Marc

Comments

  • DanikDanik Posts: 764
    Hi,
    I don't know about any existing libs to load the maps, although it should be fairly simple.
    Are you using a framework like Flixel or FlashPunk?
  • No, I'm rolling my own with Starling.  I have a system to read TMX maps though it was horrible out of the box and I had to tune it quite a bit to get the performance reasonable on smart phones.  Our artist really likes pyxel and we're looking into it.  I must admit, I'm a little surprised this is the first time this is discussed in these forums.  I can only assume there is something out there that I just haven't found yet.
  • ThndrThndr Posts: 15
    Are you asking if there is any way to use the .pyxel file as a map file?
    If that's the case it's just a zip archive with a json that holds the file info and tilemap, entire layer images, and an image per tile.
  • No Thndr, I'm looking for APIs.  A set of classes and methods used to load the map files created by Pyxel.  I don't care which language it has been developed in.  I have no problem porting it.  Though since the tool is written in AS3 I thought that this would be available in this language.
  • DanikDanik Posts: 764
    edited January 2014
    I think this depends a lot on which framework or engine you are using and how you structure your levels. For as3 the simplest is probably to use the standard JSON class.

    Example (for exported json map):

    public static function loadMap(filename:String):void {
        var mapFile:File = File.applicationDirectory.resolvePath(filename);
        var fileStream:FileStream = new FileStream();
        var bytes:ByteArray = new ByteArray();
        fileStream.open(mapFile, FileMode.READ);
        fileStream.readBytes(bytes);
       
        var mapObj:Object = JSON.parse(bytes.readUTFBytes(bytes.length));
       
        var tilesWide:int = mapObj.tileswide;
        var tilesHigh:int = mapObj.tileshigh;
        var tileWidth:int = mapObj.tilewidth;
        var tileHeight:int = mapObj.tileheight;
       
        // Initialize your tilemap data structure here
       
        var layersObj:Object = mapObj.layers;
        for each (var layerObj:Object in layersObj) {
            var layerNumber:int = layerObj.number;
            var layerName:String = layerObj.name;
            var layerTiles:Object = layerObj.tiles;
            for each (var tileObj:Object in layerTiles) {
                var x:int = tileObj.x;
                var y:int = tileObj.y;
                var tileIndex:int = tileObj.tile;
                var flipX:Boolean = tileObj.flipX;
                var rot:int = tileObj.rot;
               
                // Create/set the tile in the tilemap here
            }
        }
    }


  • Thanks Danik.  This answers my question.

    I think it might be a good idea to provide something like this and maintains it with tests that load the most up to date version of the map definition file.  Specifics of how the images are loaded and rendered need not be included as they will change from game to game. Though it might be nice to see samples of this.

    Is this project open?  Would the community be able to develop these?
  • DanikDanik Posts: 764
    That might be a good idea. I have a github repo for the project to use for issue tracking etc. It could be used for examples and supporting snippets of code like this. I will commit the example above, and anyone is free to make contributions.
    https://github.com/Danik/Pyxel-Edit
Sign In or Register to comment.