tcod.tileset

Tileset and font related functions.

Remember to add the line import tcod.tileset, as importing this module is not implied by import tcod.

class tcod.tileset.Tileset(tile_width: int, tile_height: int)[source]

A collection of graphical tiles.

This class is provisional, the API may change in the future.

__contains__(codepoint: int) → bool[source]

Test if a tileset has a codepoint with n in tileset.

get_tile(codepoint: int) → numpy.ndarray[source]

Return a copy of a tile for the given codepoint.

If the tile does not exist yet then a blank array will be returned.

The tile will have a shape of (height, width, rgba) and a dtype of uint8. Note that most grey-scale tiles will only use the alpha channel and will usually have a solid white color channel.

render(console: tcod.console.Console) → numpy.ndarray[source]

Render an RGBA array, using console with this tileset.

console is the Console object to render, this can not be the root console.

The output array will be a np.uint8 array with the shape of: (con_height * tile_height, con_width * tile_width, 4).

New in version 11.9.

set_tile(codepoint: int, tile: numpy.ndarray) → None[source]

Upload a tile into this array.

The tile can be in 32-bit color (height, width, rgba), or grey-scale (height, width). The tile should have a dtype of np.uint8.

This data may need to be sent to graphics card memory, this is a slow operation.

tile_height

The height of the tile in pixels.

tile_shape

The shape (height, width) of the tile in pixels.

tile_width

The width of the tile in pixels.

tcod.tileset.get_default() → tcod.tileset.Tileset[source]

Return a reference to the default Tileset.

New in version 11.10.

tcod.tileset.load_bdf(path: str) → tcod.tileset.Tileset[source]

Return a new Tileset from a .bdf file.

For the 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 X11 package.

Pass the returned Tileset to tcod.tileset.set_default and it will take effect when tcod.console_init_root is called.

New in version 11.10.

tcod.tileset.load_truetype_font(path: str, tile_width: int, tile_height: int) → tcod.tileset.Tileset[source]

Return a new Tileset from a .ttf or .otf file.

Same as set_truetype_font, but returns a Tileset instead. You can send this Tileset to set_default.

This function is provisional. The API may change.

tcod.tileset.set_default(tileset: tcod.tileset.Tileset) → None[source]

Set the default tileset.

The display will use this new tileset immediately.

New in version 11.10.

tcod.tileset.set_truetype_font(path: str, tile_width: int, tile_height: int) → None[source]

Set the default tileset from a .ttf or .otf file.

path is the file path for the font file.

tile_width and tile_height are the desired size of the tiles in the new tileset. The font will be scaled to fit the given tile_height and tile_width.

This function will only affect the SDL2 and OPENGL2 renderers.

This function must be called before tcod.console_init_root. Once the root console is setup you may call this funtion again to change the font. The tileset can be changed but the window will not be resized automatically.

New in version 9.2.