Inserting merged tileset into FlxAtlas
-
Hi!
I was playing with FlxAtlas class, and I wanted to add FlxTileFrames object to the atlas. I get the object from FlxTileFrames.combineTileFrames. To prevent tile tearing I use border argument set to (2, 2) (in dev branch of HaxeFlixel).I'm aware of a function FlxAtlas.addNodeWithSpacesAndBorders, that could replace the FlxTileFrames.combineTileFrames, but I want all tilesets to be placed so they are one whole FlxTileFrames that I can use with FlxTilemap (first tile in every tileset goes after the last in previous tileset).
What can be done in that regard?
-
I think you can do it this way:
var border:FlxPoint = new FlxPoint(2, 2); var tileSize:FlxPoint = new FlxPoint(tileWidth, tileHeight); var tileSpacing:FlxPoint = new FlxPoint(0, 0); var combinedTileFrames:FlxTileFrames = FlxTileFrames.combineTileFrames(tileframes, tileSpacing, border); var node:FlxNode = atlas.addNode(combinedTileFrames.parent.bitmap, "combined tiles"); var combinedTileSize:FlxPoint = new FlxPoint(tileSize.x + border.x, tileSize.y + border.y); var combinedTileFramesFromAtlas:FlxTileFrames = node.getTileFrames(combinedTileSize, tileSpacing, border); // this is the frame collection you want to use
-
@teormech Thanks, it seems to work if I add some multipliers to penultimate line like this:
var combinedTileSize:FlxPoint = new FlxPoint(tileSize.x + border.x * 2, tileSize.y + border.y * 2);
Need to eliminate some double-caching now, will post again if something goes wrong!
-
Oh, i forgot about x2.
If you don't need combinedTileFrames anymore then you can just call FlxG.bitmap.remove(combinedTileFrames.parent); and set combinedTileFrames to null
-
@teormech OK, I believe this is what I do for elements in array
tileframes
too?
-
if you won't use them anymore - then yes