Package tdl
source code
This is the official documentation for python-tdl. A Pythonic port of
libtcod.
You can find the project page on GitHub here.
Report any bugs or issues to the GitHub issue tracker here.
Getting Started
Once the library is imported you can load the font you want to use
with tdl.set_font.
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).
You may also iterate over a console using a for statement. This
returns every x,y coordinate available to draw on but it will be
extremely slow to actually operate on every coordinate individualy. Try
to minimize draws by using an offscreen Console, only drawing
what needs to be updated, and using Console.blit.
Drawing and Colors
Once you have the root console from tdl.init you can start drawing on it using a method
such as Console.draw_char. When using this method you can have
the char parameter be an integer or a single character string.
The fg and bg parameters expect a variety of types. The parameters
default to Ellipsis which will tell the function to use the colors
previously set by the Console.set_colors method. The colors set by Console.set_colors are per each Console/Window and default to
white on black. You can use a 3-item list/tuple of [red, green, blue]
with integers in the 0-255 range with [0, 0, 0] being black and [255,
255, 255] being white. You can even use a single integer of 0xRRGGBB if
you like.
Using None in the place of any of the three parameters (char, fg,
bg) will tell the function to not overwrite that color or
character.
After the drawing functions are called a call to tdl.flush will update the
screen.
Version:
1.5.2
Author:
Kyle Stewart
Contact:
4b796c65+pythonTDL@gmail.com
License:
Simplified BSD License
- 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.
|
|
Console
Contains character and color data and can be drawn to.
|
|
TDLError
The catch all for most TDL specific errors.
|
|
Window
A Window contains a small isolated part of a Console.
|
|
_BaseConsole
Contains methods shared by both the Console and Window classes.
|
|
|
|
|
int
|
|
boolean
|
|
Console
|
init(width,
height,
title=None,
fullscreen=False,
renderer=u' OPENGL ' )
Start the main console with the given width and height and return the
root console. |
source code
|
|
|
|
|
set_font(path,
columns=None,
rows=None,
columnFirst=False,
greyscale=False,
altLayout=False)
Changes the font to be used for this session. |
source code
|
|
|
|
|
|
|
|
|
int_types = ( <type 'int'>, <type 'long'>)
|
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.set_fps.
This function can only be called after tdl.init
|
Change the fullscreen resoulution
- Parameters:
|
Return the current frames per second of the running program set by set_fps
- Returns: int
- Returns the frameRate set by set_fps. If set to no limit, this
will return 0.
|
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=u' 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' over '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.
|
Capture the screen and save it as a png file
- Parameters:
|
set_font(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.
|
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.
|
Changes the fullscreen state.
- Parameters:
|
Change the window title.
- Parameters:
|