Package tdl |
[frames] | no frames]

# Package tdl

source code

The documentation for python-tdl. A Pythonic port of libtcod.

You can find the project page on Google Code here.

# Getting Started

Once the library is imported you can load the font you want to use with tdl.setFont. This is optional and when skipped will use a decent default font.

After that you call tdl.init to set the size of the window and get the root console in return. This console is the canvas to what will appear on the screen.

# Indexing Consoles

For most methods taking a position you can use Python-style negative indexes to refer to the opposite side of a console with (-1, -1) starting at the bottom right. You can also check if a point is part of a console using containment logic i.e. ((x, y) in console).

# Drawing

Once you have the root console from tdl.init you can start drawing on it using a method such as Console.drawChar. When using this method you can have the char parameter be an integer or a single character string. The fgcolor and bgcolor parameters expect a three item list [red, green, blue] with integers in the 0-255 range with [0, 0, 0] being black and [255, 255, 255] being white. Or instead you can use None for any of the three parameters to tell the library to keep what is at that spot instead of overwriting it. After the drawing functions are called a call to tdl.flush will update the screen.

Submodules
tdl.event: This module handles user input. tdl.map: Rogue-like map utilitys such as line-of-sight, field-of-view, and path-finding. tdl.noise: This module provides advanced noise generation.

Classes
| Console Contains character and color data and can be drawn to.
| TDLError The catch all for most TDL specific errors.
| Typewriter Converts a console into a scrolling text log that respects special characters.
| Window A Window contains a small isolated part of a Console.
| _MetaConsole Contains methods shared by both the Console and Window classes.

Functions
flush() Make all changes visible and update the screen. | source code
forceResolution(width, height) Change the fullscreen resoulution | source code
int |
getFPS() Return the current frames per second of the running program set by setFPS | source code
boolean |
getFullscreen() Returns True if program is fullscreen. | source code
Console |
init(width, height, title=None, fullscreen=False, renderer=`'``OPENGL``'`) Start the main console with the given width and height and return the root console. | source code
screenshot(path=None) Capture the screen and save it as a png file | source code
setFPS(frameRate) Set the maximum frame rate. | source code
setFont(path, columns=None, rows=None, columnFirst=False, greyscale=False, altLayout=False) Changes the font to be used for this session. | source code
setFullscreen(fullscreen) Changes the fullscreen state. | source code
setTitle(title) Change the window title. | source code

Function Details

### flush() | source code
Make all changes visible and update the screen. Remember to call this function after drawing operations. Calls to flush will enfore the frame rate limit set by tdl.setFPS. This function can only be called after tdl.init

### forceResolution(width, height) | source code
Change the fullscreen resoulution Parameters: `width` (int) `height` (int)

### getFPS() | source code
Return the current frames per second of the running program set by setFPS Returns: int Returns the frameRate set by setFPS. If set to no limit, this will return 0.

### getFullscreen() | source code
Returns True if program is fullscreen. Returns: boolean Returns True if the window is in fullscreen mode. Otherwise returns False.

### init(width, height, title=None, fullscreen=False, renderer=`'``OPENGL``'`) | source code
Start the main console with the given width and height and return the root console. Call the consoles drawing functions. Then remember to use tdl.flush to make what's drawn visible on the console. Parameters: `width` (int) - width of the root console (in tiles) `height` (int) - height of the root console (in tiles) `title` (string) - Text to display as the window title. If left None it defaults to the running scripts filename. `fullscreen` (boolean) - Can be set to True to start in fullscreen mode. `renderer` (string) - Can be one of 'GLSL', 'OPENGL', or 'SDL'. Due to way Python works you're unlikely to see much of an improvement by using 'GLSL' or 'OPENGL' as most of the time Python is slow interacting with the console and the rendering itself is pretty fast even on 'SDL'. Returns: Console The root console. Only what is drawn on the root console is what's visible after a call to tdl.flush. After the root console is garbage collected, the window made by this function will close.

### screenshot(path=None) | source code
Capture the screen and save it as a png file Parameters: `path` (string) - The filepath to save the screenshot. If path is None then the image will be placed in the current folder with the names: screenshot001.png, screenshot002.png, ...

### setFPS(frameRate) | source code
Set the maximum frame rate. Parameters: `frameRate` (int) - Further calls to tdl.flush will limit the speed of the program to run at <frameRate> frames per second. Can also be set to 0 to run without a limit. Defaults to None.

### setFont(path, columns=None, rows=None, columnFirst=False, greyscale=False, altLayout=False) | source code
Changes the font to be used for this session. This should be called before tdl.init If the font specifies its size in its filename (i.e. font_NxN.png) then this function can auto-detect the tileset formatting and the parameters columns and rows can be left None. While it's possible you can change the font mid program it can sometimes break in rare circumstances. So use caution when doing this. Parameters: `path` (string) - Must be a string filepath where a bmp or png file is found. `columns` (int) - Number of columns in the tileset. Can be left None for auto-detection. `rows` (int) - Number of rows in the tileset. Can be left None for auto-detection. `columnFirst` (boolean) - Defines if the characer order goes along the rows or colomns. It should be True if the charater codes 0-15 are in the first column. And should be False if the characters 0-15 are in the first row. `greyscale` (boolean) - Creates an anti-aliased font from a greyscale bitmap. Otherwise it uses the alpha channel for anti-aliasing. Unless you actually need anti-aliasing from a font you know uses a smooth greyscale channel you should leave this on False. `altLayout` (boolean) - An alternative layout with space in the upper left corner. The colomn parameter is ignored if this is True, find examples of this layout in the font/libtcod/ directory included with the python-tdl source. Raises: `TDLError` - Will be raised if no file is found at path or if auto- detection fails. Note: A png file that's been optimized can fail to load correctly on MAC OS X creating a garbled mess when rendering. Don't use a program like optipng or just use bmp files instead if you want your program to work on macs.

### setFullscreen(fullscreen) | source code
Changes the fullscreen state. Parameters: `fullscreen` (boolean)

### setTitle(title) | source code
Change the window title. Parameters: `title` (string)