Converting a tile to a bitmap?

#1

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.

0 Likes

#2

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.

0 Likes

#3

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!

0 Likes

#4

I’d also be open to more methods in Tilemap


3 Likes

#5

That would be very useful to game developers!

0 Likes