Closed Beeblerox closed 9 years ago
Idea : Add margin/spacer. For instance when loading a tilemap with its tilesheet (with margins) from TIled will results in unspaced sprites/tiles and thus wrong result. Do you wan I give an example?
@Eiyeron yes, example will be helpful to understand what you mean
Taking Kenney's Platformer Art tileset at an example :
Notice the 2px margin between the tiles. If editors like Tiled manage this, Haxeflixel won't take account of them and cut the tileset wrongly.
actually it should be supported already, but with some helper object:
var cached:CachedGraphics = FlxG.bitmap.add("assets/colortiles.png");
// top left corner of the first tile
var startX:Int = 2;
var startY:Int = 2;
// tile size
var tileWidth:Int = 10;
var tileHeight:Int = 10;
// tile spacing
var spacingX:Int = 2;
var spacingY:Int = 2;
// end of tiles
var width:Int = cached.bitmap.width - startX;
var height:Int = cached.bitmap.height - startY;
// define region
var textureRegion:TextureRegion = new TextureRegion(cached, startX, startY, tileWidth, tileHeight, spacingX, spacingY, width, height);
// and finally load it into the tilemap
add(level.loadMap(Assets.getText("assets/slopemap.txt"), textureRegion, tileWidth, tileHeight));
Thanks, I was searching and trying to edit HF to include spacer. Sorry for my poor level in Haxe and HF.
@Beeblerox That seems like a lot of extra code that is required to make that work.. I'm thinking there should be a built-in way to do this, so it works out of the box. With a Spacing:FlxPoint
param for FlxTilemap.loadMap()
and FlxSprite.loadGraphic()
maybe? Not quite sure, those functions have too many parameters already...
@Gama11 yeah, i know that i need to improve it a lot
@Eiyeron this feature isn't well known (actually i think that almost noone knows about it). so no need to sorry, because it's my fault that this feature isn't documented :)
Why not creating some helper classes which automatize some operations? loadGraphic("url", HelperClass.THIS_WAY(arguments)); ?
@Eiyeron Yeah, I've thought about this as well, seems like there's lots of repeated code across classes for graphic-loading-functionality. FlxBitmapUtil
might be suitable.
How do you do this padding stuff now? CachedGraphics and TextureRegion are gone.
Not gone, just replaced by something else. I think you're supposed to use FlxTileFrames.fromBitmapAddSpacesAndBorders()
now, but @Beeblerox is the expert.
now you have to use FlxTileFrames
class:
// top left corner of the first tile
var startX:Int = 2;
var startY:Int = 2;
// tile size
var tileSize:FlxPoint = new FlxPoint(10, 10);
// tile spacing
var tileSpacing:FlxPoint = new FlxPoint(2, 2);
// region of image to use for tiles (optional)
var region:FlxRect = new FlxRect(startX, startY);
var tiles:FlxTileFrames = FlxTileFrames.fromRectangle("assets/colortiles.png", tileSize, region, tileSpacing);
add(level.loadMap(Assets.getText("assets/slopemap.txt"), tiles));
FlxTileFrames.fromBitmapAddSpacesAndBorders()
takes spritesheet without spaces between tile images, then adds provided spaces between them and adds borders around tile images (just copies their border pixels). this method could help avoid tile tearing problem on native targets
Hi,
I can't get any of this samples working. The current docs don't mention FlxTileFrames and I don't now what kind of object level is so I can't figure what loadMap expects. Furthermore the previous example isn't too much helpful either, I'm kind of lost here :sob: Could anyone provide a more complete example?
Thanks :smile:
@vnavarro If you're not using the dev (git clone) version of HaxeFlixel you can't use FlxTileFrames, and if you aren't (i.e you use HaxeFlixel 3.3.9) you need to specify what exactly are you trying to achieve (preferably in the Google group: http://haxeflixel.com/forum/).
If you're trying to add "borders" to your spritesheet (i.e "padding") then search the issues / forum, the solution is out there :)
@vnavarro Most/all of the solutions are outdated now.
avoid creation of new bitmapDatas. this will be usefull for native targets