tilengine module¶
Python wrapper for Tilengine retro graphics engine Updated to library version 1.21.0 with log_level and input scheme from 2.1.2+ http://www.tilengine.org
-
class
tilengine.WindowFlags¶ List of flag values for window creation
-
FULLSCREEN= 1¶
-
VSYNC= 2¶
-
S1= 4¶
-
S2= 8¶
-
S3= 12¶
-
S4= 16¶
-
S5= 20¶
-
NEAREST= 64¶
-
-
class
tilengine.Flags¶ List of flags for tiles and sprites
-
FLIPX= 32768¶
-
FLIPY= 16384¶
-
ROTATE= 8192¶
-
PRIORITY= 4096¶
-
MASKED= 2048¶
-
-
class
tilengine.Error¶ List of possible error codes returned by
Engine.get_last_error()-
OK= 0¶
-
OUT_OF_MEMORY= 1¶
-
IDX_LAYER= 2¶
-
IDX_SPRITE= 3¶
-
IDX_ANIMATION= 4¶
-
IDX_PICTURE= 5¶
-
REF_TILESET= 6¶
-
REF_TILEMAP= 7¶
-
REF_SPRITESET= 8¶
-
REF_PALETTE= 9¶
-
REF_SEQUENCE= 10¶
-
REF_SEQPACK= 11¶
-
REF_BITMAP= 12¶
-
NULL_POINTER= 13¶
-
FILE_NOT_FOUND= 14¶
-
WRONG_FORMAT= 15¶
-
WRONG_SIZE= 16¶
-
UNSUPPORTED= 17¶
-
REF_LIST= 18¶
-
-
class
tilengine.LogLevel¶ Log levels for
Engine.set_log_level()-
NONE= 0¶
-
ERRORS= 1¶
-
VERBOSE= 2¶
-
-
class
tilengine.Blend¶ Available blending modes
-
NONE= 0¶
-
MIX25= 1¶
-
MIX50= 2¶
-
MIX75= 3¶
-
ADD= 4¶
-
SUB= 5¶
-
MOD= 6¶
-
CUSTOM= 7¶
-
MIX= 2¶
-
-
class
tilengine.Input¶ Available inputs to query in
Window.get_input()-
NONE= 0¶
-
UP= 1¶
-
DOWN= 2¶
-
LEFT= 3¶
-
RIGHT= 4¶
-
A= 5¶
-
B= 6¶
-
C= 7¶
-
D= 8¶
-
E= 9¶
-
F= 10¶
-
START= 11¶
-
QUIT= 12¶
-
CRT= 13¶
-
BUTTON1= 5¶
-
BUTTON2= 6¶
-
BUTTON3= 7¶
-
BUTTON4= 8¶
-
BUTTON5= 9¶
-
BUTTON6= 10¶
-
P1= 0¶
-
P2= 32¶
-
P3= 64¶
-
P4= 96¶
-
-
class
tilengine.Overlay¶ Available CRT overlay patterns
-
NONE= 0¶
-
SHADOWMASK= 1¶
-
APERTURE= 2¶
-
SCANLINES= 3¶
-
CUSTOM= 4¶
-
-
exception
tilengine.TilengineException(value)¶ Tilengine exception class
-
class
tilengine.Tile¶ Tile data contained in each cell of a
Tilemapobjectindex: tile indexflags: sum ofFlagsvalues-
flags¶ Structure/Union member
-
index¶ Structure/Union member
-
-
class
tilengine.ColorStrip(delay, first, count, direction)¶ Data used to define each frame of a color cycle for
Sequenceobjects-
delay¶ Structure/Union member
-
first¶ Structure/Union member
-
count¶ Structure/Union member
-
dir¶ Structure/Union member
-
-
class
tilengine.SequenceInfo¶ Sequence info returned by
Sequence.get_info()-
name¶ Structure/Union member
-
num_frames¶ Structure/Union member
-
-
class
tilengine.SequenceFrame(index, delay)¶ Data used to define each frame of an animation for
Sequenceobjects-
index¶ Structure/Union member
-
delay¶ Structure/Union member
-
-
class
tilengine.SpriteInfo¶ Data returned by
Spriteset.get_sprite_info()with dimensions of the required sprite-
h¶ Structure/Union member
-
w¶ Structure/Union member
-
-
class
tilengine.TileInfo¶ Data returned by
Layer.get_tile()about a given tile inside a background layer-
col¶ Structure/Union member
-
color¶ Structure/Union member
-
empty¶ Structure/Union member
-
flags¶ Structure/Union member
-
index¶ Structure/Union member
-
row¶ Structure/Union member
-
type¶ Structure/Union member
-
xoffset¶ Structure/Union member
-
yoffset¶ Structure/Union member
-
-
class
tilengine.SpriteData(name, x, y, width, height)¶ Data used to create
Spritesetobjects-
name¶ Structure/Union member
-
x¶ Structure/Union member
-
y¶ Structure/Union member
-
w¶ Structure/Union member
-
h¶ Structure/Union member
-
-
class
tilengine.TileAttributes(tile_type, priority)¶ Data used to create
Tilesetobjects-
type¶ Structure/Union member
-
priority¶ Structure/Union member
-
-
class
tilengine.PixelMap¶ Data passed to
Layer.set_pixel_mapping()in a list-
dx¶ Structure/Union member
-
dy¶ Structure/Union member
-
-
class
tilengine.ObjectInfo¶ Object item info returned by
ObjectInfo.get_info()-
flags¶ Structure/Union member
-
gid¶ Structure/Union member
-
height¶ Structure/Union member
-
id¶ Structure/Union member
-
name¶ Structure/Union member
-
type¶ Structure/Union member
-
visible¶ Structure/Union member
-
width¶ Structure/Union member
-
x¶ Structure/Union member
-
y¶ Structure/Union member
-
-
class
tilengine.TileImage¶ Image Tile items for TLN_CreateImageTileset()
-
bitmap¶ Structure/Union member
-
id¶ Structure/Union member
-
type¶ Structure/Union member
-
-
class
tilengine.SpriteState¶ Sprite state for
Sprite.get_state()-
collision¶ Structure/Union member
-
enabled¶ Structure/Union member
-
flags¶ Structure/Union member
-
h¶ Structure/Union member
-
index¶ Structure/Union member
-
palette¶ Structure/Union member
-
spriteset¶ Structure/Union member
-
w¶ Structure/Union member
-
x¶ Structure/Union member
-
y¶ Structure/Union member
-
-
class
tilengine.Color(r, g, b)¶ Represents a color value in RGB format
-
classmethod
fromstring(string)¶ creates a color from a ccs-style #rrggbb string
-
classmethod
-
class
tilengine.Engine(handle, num_layers, num_sprites, num_animations)¶ Main object for engine creation and rendering
Variables: - layers – tuple of Layer objects, one entry per layer
- sprites – tuple of Sprite objects, one entry per sprite
- animations – tuple of Animation objects, one entry per animation
- version – library version number
-
classmethod
create(width, height, num_layers, num_sprites, num_animations)¶ Static method that creates a new instance of the engine
Parameters: - width – horizontal resolution in pixels
- height – vertical resolution in pixels
- num_layers – max number of background layers
- num_sprites – max number of sprites
- num_animations – number of color-cycle animations
Returns: new instance
-
get_num_objects()¶ Returns: the number of objets used by the engine so far
-
get_used_memory()¶ Returns: the total amount of memory used by the objects
-
set_background_color(param)¶ Sets the background color
Parameters: param – can be a Color object or a Tilemap object. In this case, it assigns de background color as defined inside the tilemap
-
disable_background_color()¶ Disales background color rendering. If you know that the last background layer will always cover the entire screen, you can disable it to gain some performance
-
set_background_bitmap(bitmap)¶ Sets a static bitmap as background
Parameters: bitmap – Bitmap object to set as background. Set None to disable it.
-
set_background_palette(palette)¶ Sets the palette for the background bitmap. By default it is assigned the palette of the bitmap passed in
Engine.set_background_bitmap()Parameters: palette – Palette object to set
-
set_raster_callback(raster_callback)¶ Enables raster effects processing, like a virtual HBLANK interrupt where any render parameter can be modified between scanlines.
Parameters: raster_callback – name of the user-defined function to call for each scanline. Set None to disable. This function takes one integer parameter that indicates the current scanline, between 0 and vertical resolution. Example:
def my_raster_callback(num_scanline): if num_scanline is 32: engine.set_background_color(Color(0,0,0)) engine.set_raster_callback(my_raster_callback)
-
set_frame_callback(frame_callback)¶ Enables user callback for each drawn frame, like a virtual VBLANK interrupt
Parameters: frame_callback – name of the user-defined function to call for each frame. Set None to disable. This function takes one integer parameter that indicates the current frame. Example:
def my_frame_callback(num_frame): engine.set_background_color(Color(0,0,0)) engine.set_frame_callback(my_frame_callback)
-
set_render_target(pixels, pitch)¶ Sets the output surface for rendering
Parameters: - pixels – Pointer to the start of the target framebuffer
- pitch – Number of bytes per each scanline of the framebuffer
-
update_frame(num_frame=0)¶ Draws the frame to the previously specified render target
Parameters: num_frame – optional frame number for animation control
-
set_load_path(path)¶ Sets base path for all data loading static methods fromfile
Parameters: path – Base path. Files will load at path/filename. Set None to use current directory
-
set_custom_blend_function(blend_function)¶ Sets custom blend function to use in sprites or background layers when BLEND_CUSTOM mode is selected with the
Layer.set_blend_mode()andSprite.set_blend_mode()methods.Parameters: blend_function – name of the user-defined function to call when blending that takes two integer arguments: source component intensity, destination component intensity, and returns the desired intensity. Example:
# do 50%/50% blending def blend_50(src, dst): return (src + dst) / 2 engine.set_custom_blend_function(blend_50)
-
set_log_level(log_level)¶ Sets output messages
-
get_available_sprite()¶ Returns: Index of the first unused sprite (starting from 0) or -1 if none found
-
get_available_animation()¶ Returns: Index of the first unused animation (starting from 0) or -1 if none found
-
open_resource_pack(filename, key)¶ Opens the resource package with optional aes-128 key and binds it :param filename: file with the resource package (.dat extension) :param key: optional null-terminated ASCII string with aes decryption key
-
close_resource_pack()¶ Closes currently opened resource package and unbinds it
-
set_sprites_mask_region(top, bottom)¶ Defines a sprite masking region between the two scanlines. Sprites masked with Sprite.enable_mask_region() won’t be drawn inside this region
Parameters: - top – upper scaline of the exclusion region
- bottom – lower scanline of the exclusion region
-
load_world(filename, first_layer=0)¶ Loads and assigns complete TMX file
Parameters: filename – main .tmx file to load First_layer: optional layer index to start to assign, by default 0
-
set_world_position(x, y)¶ Sets global world position, moving all layers in sync according to their parallax factor
Parameters: - x – horizontal position in world space
- y – vertical position in world space
-
release_world()¶ Releases world resources loaded with Engine.load_world
-
class
tilengine.Window¶ Built-in window manager for easy setup and testing
Variables: -
classmethod
create(title='Tilengine window', overlay=None, flags=2)¶ Static method that creates a single-threaded window that must be used in conjunction with
Window.process()in a loopParameters: - overlay – name of an optional bitmap for use as overlay by the CRT effect
- flags – optional flags combination of
WindowFlagsvalues
Returns: instance of the created window
-
classmethod
create_threaded(overlay=None, flags=2)¶ Static method that creates a multi-threaded window that runs in its own thread without user loop. Used mainly in python interactive console
Parameters: - overlay – name of an optional bitmap for use as overlay by the CRT effect
- flags – optional flags combination of
WindowFlagsvalues
-
process()¶ Does basic window housekeeping in signgle-threaded window, created with
Window.create(). This method must be called in a loop by the main thread. :return: True if window is active or False if the user has requested to end the application (by pressing Esc key or clicking the close button)
-
is_active()¶ Returns: True if window is active or False if the user has requested to end the application (by pressing Esc key or clicking the close button)
-
get_input(input_id)¶ Returns the state of a given input
Parameters: input_id – one of the Inputdefined values. By default it requests input of player 1. To request input of a given player, add one of the possible P1 - P4 values.Returns: True if that input is pressed or False if not Example:
# check if player 1 is pressing right: value = window.get_input(Input.RIGHT) # check if player 2 is pressing action button 1: value = window.get_input(Input.P2 + Input.BUTTON1)
-
enable_input(player, state)¶ Enables or disables input for specified player
Parameters: - player – player identifier to configure (PLAYER1 - PLAYER4)
- state – True to enable, False to disable
-
assign_joystick(player, joystick_index)¶ Parameters: - player – player identifier to configure (PLAYER1 - PLAYER4)
- joystick_index – zero-based joystick index to assign. 0 = first, 1 = second…. Disable with -1
-
define_input_key(player, input, key)¶ Assigns a keyboard input to a player
Parameters: - player – player identifier to configure (PLAYER1 - PLAYER4)
- input – input to assign, member of
Input
Assigns a joystick button input to a player
Parameters: - player – player identifier to configure (PLAYER1 - PLAYER4)
- input – input to assign, member of
Input
-
draw_frame(num_frame=0)¶ Deprecated, kept for old source code compatibility. Subsumed by
Window.process().
-
wait_redraw()¶ In multi-threaded windows, it waits until the current frame has finished rendering.
-
enable_crt_effect(overlay_id, overlay_blend, threshold, v0, v1, v2, v3, blur, glow_factor)¶ Enables CRT simulation post-processing effect to give true retro appearance. Enabled by default.
Parameters: - overlay_id – One of the defined
Overlayvalues. Choosing Overlay.CUSTOM selects the image passed when callingWindow.create() - overlay_blend – blend factor for overlay image. 0 is full transparent (no effect), 255 is full blending
- threshold – Middle point of the brightness mapping function
- v0 – output brightness when input brightness = 0
- v1 – output brightness when input brightness = threshold
- v2 – output brightness when input brightness = threshold (to create discontinuity with v1)
- v3 – output brightness when input brightness = 255
- blur – True to add gaussian blur to brightness overlay, softens image
- glow_factor – blend addition factor for brightness overlay. 0 is not addition, 255 is full addition
- overlay_id – One of the defined
-
disable_crt_effect()¶ Disables the CRT post-processing effect enabled with
Window.enable_crt_effect()
-
set_sdl_callback(sdl_callback)¶
-
get_ticks()¶ Returns: the number of milliseconds since application start
-
delay(msecs)¶ Suspends execition for a fixed time
Parameters: msecs – number of milliseconds to pause
-
classmethod
-
class
tilengine.Spriteset(handle, owner=True)¶ The Spriteset object holds the graphic data used to render moving objects (sprites)
Variables: palette – original palette attached inside the resource file -
classmethod
create(bitmap, sprite_data)¶ Static method that creates an empty spriteset
Parameters: - bitmap – Bitmap object containing the packaged sprite pictures
- sprite_data – list of SpriteEntry tuples describing each sprite pictures
Returns: instance of the created object
-
classmethod
fromfile(filename)¶ Static method that loads a spriteset from a pair of png/txt files
Parameters: filename – png filename with bitmap data Returns: instance of the created object
-
clone()¶ Creates a copy of the object
Returns: instance of the copy
-
set_sprite_data(entry, data, pixels, pitch)¶ Sets attributes and pixels of a given sprite inside a spriteset
Parameters: - entry – The entry index inside the spriteset to modify [0, num_sprites - 1]
- data – Pointer to a user-provided SpriteData structure with sprite description
- pixels – Pointer to user-provided pixel data block
- pitch – Number of bytes per scanline of the source pixel data
-
get_sprite_info(entry, info)¶ Gets info about a given sprite into an user-provided SpriteInfo tuple
Parameters: - entry – sprite index to query
- info – SpriteInfo to get the data
-
classmethod
-
class
tilengine.Tileset(handle, owner=True)¶ The Tileset object holds the graphic tiles used to render background layers from a Tilemap
Variables: - tile_width – width of each tile
- tile_height – height of each tile
- num_tiles – number of unique tiles
- palette – original palette attached inside the resource file
- sequence_pack – optional SequencePack embedded inside the Tileset for tileset animation
-
classmethod
create(num_tiles, width, height, palette, sequence_pack=None, attributes=None)¶ Static method that creates an empty Tileset at runtime
Parameters: - num_tiles – number of unique tiles
- width – Width of each tile (must be multiple of 8)
- height – Height of each tile (must be multiple of 8)
- palette – Palette object
- sequence_pack – Optional SequencePack with associated Tileset animations
- attributes – Optional list of attributes, one element per tile in the tileset
Returns: instance of the created object
-
classmethod
fromfile(filename)¶ Static method that loads a Tiled TSX tileset from file
Parameters: filename – TSX file with the tileset Returns:
-
clone()¶ Creates a copy of the object
Returns: instance of the copy
-
set_pixels(entry, data, pitch)¶ Sets pixel data for a single tile
Parameters: - entry – Number of tile to set [0, num_tiles - 1]
- data – List of bytes with pixel data, one byte per pixel
- pitch – Number of bytes per line in source data
-
class
tilengine.Tilemap(handle, owner=True)¶ The Tilemap object holds the grid of tiles that define the background layout
Variables: - rows – number of rows (vertical cells)
- cols – number of columns (horizontal cells)
- tileset – Tileset object attached inside the resource file
-
classmethod
create(rows, cols, tiles, background_color=0, tileset=None)¶ Static method that creates an empty tilemap
Parameters: - rows – Number of rows (vertical dimension)
- cols – Number of cols (horizontal dimension)
- tiles – List of Tile objects with tile data
- background_color – optional Color object with default background color
- tileset – Optional reference to associated tileset
Returns: instance of the created object
-
classmethod
fromfile(filename, layer_name=None)¶ Static method that loads a Tiled TMX tilemap from file
Parameters: - filename – TMX file with the tilemap
- layer_name – Optional name of the layer to load when the TMX file has more than one layer. By default it loads the first layer inside the TMX
Returns: instance of the created object
-
clone()¶ Creates a copy of the object
Returns: instance of the copy
-
get_tile(row, col, tile_info)¶ Gets data about a given tile
Parameters: - row – Vertical position of the tile (0 <= row < rows)
- col – Horizontal position of the tile (0 <= col < cols)
- tile_info – pointer to user-provided
Tileobject where to get the data
-
set_tile(row, col, tile_info)¶ Sets a tile inside the tilemap
Parameters: - row – Vertical position of the tile (0 <= row < rows)
- col – Horizontal position of the tile (0 <= col < cols)
- tile_info – pointer to user-provided
Tileobject, or None to erase
-
copy_tiles(src_row, src_col, num_rows, num_cols, dst_tilemap, dst_row, dst_col)¶ Copies blocks of tiles between two tilemaps
Parameters: - src_row – Starting row (vertical position) inside the source tilemap
- src_col – Starting column (horizontal position) inside the source tilemap
- num_rows – Number of rows to copy
- num_cols – Number of columns to copy
- dst_tilemap – Target tilemap
- dst_row – Starting row (vertical position) inside the target tilemap
- dst_col – Starting column (horizontal position) inside the target tilemap
-
class
tilengine.Palette(handle, owner=True)¶ The Palette object holds the color tables used by tileesets and spritesets to render sprites and backgrounds
-
classmethod
create(num_entries=256)¶ Static method that creates an empty palette
Parameters: num_entries – optional number of colors to hold (up to 256, default value) Returns: instance of the created object
-
classmethod
fromfile(filename)¶ Static method that loads a palette from an Adobe Color Table (.act) file
Parameters: filename – name of the .act file to load Returns: instance of the created object
-
clone()¶ Creates a copy of the object
Returns: instance of the copy
-
set_color(entry, color)¶ Sets the RGB color value of a palette entry
Parameters: - entry – Index of the palette entry to modify (0-255)
- color – Color object with the r,g,b components of the color
-
mix(src_palette1, src_palette2, factor)¶ Mixes two palettes
Parameters: - src_palette1 – First palette to mix
- src_palette2 – Second palette to mix
- factor – Integer value with percentage of mix (0-100)
-
add_color(first, count, color)¶ Modifies a range of colors by adding the provided color value to the selected range. The result is always a brighter color.
Parameters: - first – index of the first color entry to modify
- count – number of colors from start to modify
- color – Color object to add
-
sub_color(first, count, color)¶ Modifies a range of colors by subtracting the provided color value to the selected range. The result is always a darker color.
Parameters: - first – index of the first color entry to modify
- count – number of colors from start to modify
- color – Color object to subtract
-
mod_color(first, count, color)¶ Modifies a range of colors by modulating (normalized product) the provided color value to the selected range. The result is always a darker color.
Parameters: - first – index of the first color entry to modify
- count – number of colors from start to modify
- color – Color object to modulate
-
classmethod
-
class
tilengine.Bitmap(handle, owner=True)¶ The Bitmap object holds graphic data used to build in backgrounds, Tileset and Spriteset objects
Variables: -
classmethod
create(width, height, bpp=8)¶ Static method that creates an empty bitmap
Parameters: - width – Width in pixels
- height – Height in pixels
- bpp – Optional bits per pixel (8 by default)
Returns: instance of the created object
-
classmethod
fromfile(filename)¶ Static method that loads a BMP or PNG file
Parameters: filename – name of the file to load (.bmp or .png) Returns: instance of the created object
-
clone()¶ Creates a copy of the object
Returns: instance of the copy
-
get_data(x, y)¶ Returns a pointer to the starting memory address
Parameters: - x – Starting x position [0, width - 1]
- y – Starting y position [0, height - 1]
Returns: pointer
-
classmethod
-
class
tilengine.ObjectList¶ ObjectList reference
-
class
tilengine.Sequence(handle, owner=True)¶ The Sequence object holds the sequences to feed the animation engine
-
classmethod
create_sequence(name, target, frames)¶ Static method that creates an empty Sequence for Sprite and Tileset animations
Parameters: - name – String with an unique name to identify the sequence inside a SequencePack object
- target – For Tileset animations, the tile index to animate
- frames – List with SequenceFrame objects, one for each frame of animation
Returns: instance of the created object
-
classmethod
create_cycle(name, strips)¶ Static method that creates an empty Sequence for Palette animations
Parameters: - name – String with an unique name to identify the sequence inside a SequencePack object
- strips – List with ColorStrip objects, one for each frame of animation
Returns: instance of the created object
-
classmethod
create_sprite_sequence(spriteset, basename, delay)¶ Static method that creates a sprite sequence based on names inside a spriteset
Parameters: - spriteset – Reference to the spriteset with frames to animate
- basename – Base of the sprite name for the numbered sequence
- delay – Number of frames to hold each animation frame
Returns: created Sequence object or None if error
-
clone()¶ Creates a copy of the object
Returns: instance of the copy
-
get_info(info)¶ Returns runtime info about a given sequence
Parameters: info – user-provided SequenceInfo structure to hold the returned data
-
classmethod
-
class
tilengine.SequencePack(handle, owner=True)¶ The SequencePack object holds a collection of Sequence objects
Variables: - count – number of sequences inside the pack
- sequences – dictionary of contained sequences indexed by name
-
classmethod
create()¶ Static method that creates an empty SequencePack object
Returns: instance of the created object
-
classmethod
fromfile(filename)¶ Static method that loads a SQX file with sequence data (XML-based)
Parameters: filename – Name of the SQX file to load Returns: instance of the created object
-
get_sequence(index)¶ Returns the nth sequence inside a sequence pack
Parameters: index – zero-based index number Returns: Sequence object
-
find_sequence(name)¶ Finds a Sequence by its name
Parameters: name – name of the Sequence to find Returns: Sequence object if found, or None if error
-
add_sequence(sequence)¶ Adds a Sequence to a SequencePack
Parameters: sequence – Sequence object to add
-
class
tilengine.Layer(index)¶ The Layer object manages each tiled background plane
Variables: - index – layer index, from 0 to num_layers - 1
- width – width in pixels of the assigned tilemap
- height – height in pixels of the assigned tilemap
- tilemap – assigned Tilemap object, for tilemap layers
- bitmap – assigned Bitmap object, for bitmap layers
- objectlist – assigned ObjectList object, for object list layers
-
setup(tilemap, tileset=None)¶ Enables a background layer by setting the specified tilemap and optional tileset
Parameters: - tilemap – Tilemap object with background layout
- tileset – Optional Tileset object. If not set, the Tilemap’s own Tileset is selected
-
set_tilemap(tilemap)¶ Configures a tiled background layer with the specified tilemap
Parameters: tilemap – Tilemap object with background layout
-
set_bitmap(bitmap)¶ Configures a background layer with the specified full bitmap
Parameters: bitmap – Bitmap object with full bitmap background
-
set_palette(palette)¶ Sets the color palette to the layer
Parameters: palette – Palette object to assign. By default the Tileset’s own palette is used
-
set_position(x, y)¶ Sets the position of the tileset that corresponds to the upper left corner of the viewport
Parameters: - x – horizontal position
- y – vertical position
-
set_scaling(sx, sy)¶ Enables layer scaling
Parameters: - sx – floating-point value with horizontal scaling factor
- sy – floating-point value with vertical scaling factor
-
set_transform(angle, x, y, sx, sy)¶ Enables layer affine transformation (rotation and scaling). All parameters are floating point values
Parameters: - angle – rotation angle in degrees
- x – horizontal displacement in screen space where the rotation center is located
- y – vertical displacement in screen space where the rotation center is located
- sx – horizontal scaling factor
- sy – vertical scaling factor
-
set_pixel_mapping(pixel_map)¶ Enables pixel mapping displacement table
Parameters: pixel_map – user-provided list of PixelMap objects of hres*vres size: one item per screen pixel
-
reset_mode()¶ Disables all special effects: scaling, affine transform and pixel mapping, and returns to default render mode.
-
set_blend_mode(mode)¶ Enables blending mode with background objects
Parameters: mode – One of the Blenddefined values
-
set_column_offset(offsets)¶ Enables column offset mode for tiles
Parameters: offsets – User-provided list of integers with offsets, one per column of tiles. Pass None to disable
-
set_clip(x1, y1, x2, y2)¶ Enables clipping rectangle
Parameters: - x1 – left coordinate
- y1 – top coordinate
- x2 – right coordinate
- y2 – bottom coordinate
-
disable_clip()¶ Disables clipping rectangle
-
set_mosaic(pixel_w, pixel_h)¶ Enables mosaic effect (pixelation)
Parameters: - pixel_w – horizontal pixel size
- pixel_h – vertical pixel size
-
disable_mosaic()¶ Disables mosaic effect
-
disable()¶ Disables the layer so it is not drawn
-
enable()¶ Re-enables previously disabled layer
-
get_palette()¶ Gets the layer active palette
Returns: Palette object of the Layer
-
get_tile(x, y, tile_info)¶ Gets detailed info about the tile located in Tilemap space
Parameters: - x – x position inside the Tilemap
- y – y position inside the Tilemap
- tile_info – User-provided TileInfo object where to get the data
-
set_priority(enable)¶ Sets full layer priority, appearing in front of regular sprites
Parameters: enable – True for enable, False for disable
-
set_parallax_factor(x, y)¶ Sets layer parallax factor to use in conjunction with Engine.set_world_position()
Parameters: - x – Horizontal parallax factor
- y – Vertical parallax factor
-
class
tilengine.Sprite(index)¶ The Sprite object manages each moving character onscreen
Variables: -
setup(spriteset, flags=0)¶ Enables a sprite by setting its Spriteset and optional flags
Parameters: - spriteset – Spriteset object with the graphic data of the sprites
- flags – Optional combination of defined
Flagvalues, 0 by default
-
set_spriteset(spriteset)¶ Enables a sprite by setting its Spriteset
Parameters: spriteset – Spriteset object with the graphic data of the sprites
-
set_flags(flags)¶ Sets modification flags
Parameters: flags – Combination of defined Flagvalues
-
enable_flag(flag, value=True)¶ Enables (or disables) specified flag for a sprite
Parameters: - flag – Combination of defined
Flagvalues - value – True to enable (default) or False to disable
- flag – Combination of defined
-
set_pivot(u, v)¶ Sets sprite pivot point for placement and scaling source. By default is at (0,0) = top left corner. Uses normalized coordinates in [ 0.0 - 1.0] range.
Parameters: - u – Horizontal position (0.0 = full left, 1.0 = full right)
- v – Vertical position (0.0 = top, 1.0 = bottom)
-
set_position(x, y)¶ Sets the sprite position in screen coordinates
Parameters: - x – Horizontal position
- y – Vertical position
-
set_world_position(x, y)¶ Sets the sprite position in world space coordinates
Parameters: - x – Horizontal world position of pivot (0 = left margin)
- y – Vertical world position of pivot (0 = top margin)
-
set_picture(picture)¶ Sets the actual graphic contained in the Spriteset to the sprite
Parameters: picture – can be an integer with the index inside the Spriteset, or a string with its name
-
set_palette(palette)¶ Assigns a Palette object to the sprite. By default it is assigned wit the Spriteset’s own palette
Parameters: palette – Palette object to set
-
set_blend_mode(mode)¶ Enables blending mode with background objects
Parameters: mode – One of the Blenddefined values
-
set_scaling(sx, sy)¶ Enables sprite scaling
Parameters: - sx – floating-point value with horizontal scaling factor
- sy – floating-point value with vertical scaling factor
-
reset_mode()¶ Disables scaling and returns to default render mode.
-
get_picture()¶ Returns the index of the assigned picture from the Spriteset
Returns: the graphic index
-
enable_collision(mode)¶ Enables pixel-accurate sprite collision detection with other sprites
Parameters: mode – True for enabling or False for disabling
-
check_collision()¶ Gets the collision status of the sprite. Requires
Sprite.enable_collision()set to TrueReturns: True if collision with another sprite detected, or False if not
-
disable()¶ Disables the sprite so it is not drawn
-
get_palette()¶ Gets the sprite active palette
Returns: Palette object of the Sprite
-
set_animation(sequence, loop)¶ Starts a Sprite animation
Parameters: - sequence – Sequence object to play on the sprite
- loop – number of times to repeat, 0=infinite
-
get_animation_state()¶ Gets the state of the animation
Returns: True if still running, False if it has finished
-
disable_animation()¶ Disables the animation so it doesn’t run
-
get_state(state)¶ Returns runtime info about the sprite
Parameters: state – user-allocated SpriteState structure
-
set_first()¶ Sets this to be the first sprite drawn (beginning of list)
-
set_next(next)¶ Sets the next sprite to after this one, builds list
Parameters: next – sprite to draw after this one
-
enable_masking(enable)¶ Enables or disables masking for this sprite, if enabled it won’t be drawn inside the region set up with Engine.set_sprite_mask_region()
-
-
class
tilengine.Animation(index)¶ The Animation object manages color-cycle (palette) animations
Variables: index – animation index, from 0 to num_animations - 1 -
set_palette_animation(palette, sequence, blend)¶ Starts a color cycle animation for Palette object
Parameters: - palette – Palette object to animate
- sequence – Sequence object to play on the palette
- blend – True for smooth frame interpolation, False for classic coarse mode
-
set_palette_animation_source(palette)¶ Sets the source palette of a color cycle animation already in motion. Useful for combining color cycling and palette interpolation at the same time
Parameters: palette – Palette object to assign
-
disable()¶ Disables the animation so it doesn’t run
-