Load more than one spritesheet with FlxTilemap

  • I would like to know if it's possible to load a FlxTilemap using more than one spritesheet (all loadMap* functions accept only one TileGraphic object).


  • Yes, you should use FlxTileFrames (in my case I work with Tiled wrapper classes from flixel-addons):

    var tileSize: FlxPoint = FlxPoint.get(tileMap.tileWidth, tileMap.tileHeight);
    var tilesetTileFrames: Array<FlxTileFrames> = new Array<FlxTileFrames>();
    for (tileset in tileMap.tilesetArray)
        tilesetTileFrames.push(FlxTileFrames.fromRectangle("assets/data/" + tileset.imageSource, tileSize);
    var tileSpacing: FlxPoint = FlxPoint.get(0, 0);
    var tileBorder: FlxPoint = FlxPoint.get(2, 2);
    var mergedTileset = FlxTileFrames.combineTileFrames(tilesetTileFrames, tileSpacing, tileBorder);

    After that you can use mergedTileset as your graphic.
    Note that tileSpacing and tileBorder parameters are recently added in the dev branch of Flixel and serve to fix tile tearing on native targets.

    Also it's a simplified version of my real code, so let me excuse if it doesn't compile out-of-the-box or something :-)

  • administrators

    No, you would have to combine your spritesheets into one graphic. You can use FlxTileFrames.combineTileSets()for that. The result is a FlxTileFrames object, which extends FlxFramesCollection, which is one of the accepted types for FlxTilemapGraphicAsset.

    Edit: looks like I was ninja'd by @starry-abyss. :)

  • Great, thanks for the help! :smile:

Log in to reply