NAME

TCOD::Tileset - Font loading functions

SYNOPSIS

use TCOD;
use File::Share 'dist_file';

my $tileset = TCOD::Tileset->load_tilesheet(
    path    => dist_file( TCOD => 'arial10x10.png' ),
    columns => 32,
    rows    => 8,
    charmap => TCOD::CHARMAP_TCOD,
);

DESCRIPTION

Tilesets encapsulate font loading functions.

Tilesets can be loaded as a whole from tile-sheets or True-Type fonts.

METHODS

load_tilesheet

$tileset = TCOD::Tileset->load_tilesheet( $path, $cols, $rows, $charmap );
$tileset = TCOD::Tileset->load_tilesheet(
    path    => $path,
    columns => $cols,
    rows    => $rows,
    charmap => $charmap,
);

Return a new TCOD::Tileset from a simple tilesheet PNG image. The location of this file in disk is specified in path.

The values in columns and rows is the shape of the tileset. Tiles are assumed to take up the entire space of the image.

The value in charmap is the character mapping to use. This is an array reference of codepoints which map the tiles like this:

$charmap->[ $tile_index ] = $codepoint

For common tilesets, charmap should be the value in TCOD::CHARMAP_CP437. If you're using tilesets using the standard TCOD layout, then you can set it to TCOD::CHARMAP_TCOD.

There is no default value. If no value is provided, no tiles will be mapped. In this case, you'll need to use remap to assign codepoints to this tileset.

This function accepts named parameters, but can also be called with the path, columns, rows, and charmap parameters as positional, in that order.

load_bdf

$tileset = TCOD::Tileset->load_bdf( $path );

Return a new TCOD::Tileset from a .bdf file.

For best results, the font should be monospace, cell-based, and single-width. As an example, a good set of fonts would be the Unicode fonts and tools for the X11 package.

tile_shape

( $width, $height ) = $tileset->tile_shape;

Returns a list with the width and height of the tile in pixels.

remap

$tileset->remap( $x, $y, $codepoint );

Reassign the Unicode codepoint specified in $codepoint to the character in this tilesheet at the position specified by the $x and $y coordinates.

This is the tile position itself, not the pixel position of the tile. Large values of $x will wrap to the next row, so using $x by itself is equivalent to Tile Index in the python-tcod Character Table Reference.

This is normally used on loaded tilesheets. Other methods of TCOD::Tileset creation won't have reliable tile indices.

SEE ALSO

TCOD
TCOD::Context

COPYRIGHT AND LICENSE

Copyright 2021 José Joaquín Atria

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.