GTextureAtlas.fixedSizeTile constructor
GTextureAtlas.fixedSizeTile(})
Constructs a new instance of GTextureAtlas with the provided tile size and texture.
The tileWidth
and tileHeight
arguments define the size of each tile
in the atlas.
The tilePadding
argument sets the amount of padding to add around each
tile.
The namePrefix
argument sets the prefix to use for the name of each
tile.
Throws an error if the texture
is null
.
Implementation
factory GTextureAtlas.fixedSizeTile(
GTexture texture, {
required double tileWidth,
double? tileHeight,
double tilePadding = 0,
String namePrefix = '',
}) {
tileHeight ??= tileWidth;
final atlas = GTextureAtlas(texture);
final cols = texture.width! ~/ tileWidth;
final rows = texture.height! ~/ tileHeight;
final total = cols * rows;
List.generate(total, (index) {
var px = index % cols;
var py = index ~/ cols;
final name = '$namePrefix$index'.padLeft(2, '0');
atlas.addRegion(
name,
GRect(
px * tileWidth + tilePadding,
py * tileHeight! + tilePadding,
tileWidth - tilePadding,
tileHeight - tilePadding,
),
);
});
return atlas;
}