Is there a quick way to convert a tile to a bitmap?
I’m pulling objects off of a tilesheet that I need to do collision detection on.
Is there a quick way to convert a tile to a bitmap?
I’m pulling objects off of a tilesheet that I need to do collision detection on.
Maybe something like this?
function tileToBitmap(tile:openfl.display.Tile):openfl.display.Bitmap {
var rect = tile.tileset.getRect(id);
var bitmapData = new openfl.display.BitmapData(cast rect.width, cast rect.height, true, 0x0);
bitmapData.copyPixels(tile.tileset.bitmapData, rect, new openfl.geom.Point(), null, null, true);
return new openfl.display.Bitmap(bitmapData);
}
Would be very bad for collision detection though. For pixel-perfect checking I think you should try checking directly within tileset.bitmapData. I think do an inversion of a checking point on a tile with its global matrix (__getWorldTransform()?) if needed, then using the tile rect you can find the original pixel to check for its alpha. Or if possible, use a library like differ.
Fortunately the tile I am wanting to convert is a rectangle, so collisions will not be a problem. I’ll wire this up later this afternoon. Thank you!
I’d also be open to more methods in Tilemap
That would be very useful to game developers!
I’m just checking back with this topic to see if there has been any new developments with tiles/maps and hittesting or conversions to bitmaps.