Package tdl |
[frames] | no frames]

# Package tdl

source code

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

# Getting Started

Once the library is imported you can load the font you want to use with tdl.setFont. This is optional and can be skipped to get 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.

# 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 intiger 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.

Classes
| Console The Console is the main class of the tdl library.
| TDLError The catch all for most TDL specific errors.
| 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=`'``python-tdl``'`, 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, tileWidth, tileHeight, colomn=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=`'``python-tdl``'`, 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: `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'. This should be left at default or switched to 'SDL' for better reliability and an instantaneous start up time. `width` (int) `title` (string) `height` (int) 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, tileWidth, tileHeight, colomn=False, greyscale=False, altLayout=False) | source code
Changes the font to be used for this session. This should be called before tdl.init 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. `tileWidth` (int) - The width of an individual tile. `tileHeight` (int) - The height of an individual tile. `colomn` (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. `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/ directory included with the python-tdl source. Raises: `TDLError` - Will be raised if no file is found at path. 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)